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
,
137 QEMU_IFLA_ALT_IFNAME
,
138 QEMU_IFLA_PERM_ADDRESS
,
143 QEMU_IFLA_BRPORT_UNSPEC
,
144 QEMU_IFLA_BRPORT_STATE
,
145 QEMU_IFLA_BRPORT_PRIORITY
,
146 QEMU_IFLA_BRPORT_COST
,
147 QEMU_IFLA_BRPORT_MODE
,
148 QEMU_IFLA_BRPORT_GUARD
,
149 QEMU_IFLA_BRPORT_PROTECT
,
150 QEMU_IFLA_BRPORT_FAST_LEAVE
,
151 QEMU_IFLA_BRPORT_LEARNING
,
152 QEMU_IFLA_BRPORT_UNICAST_FLOOD
,
153 QEMU_IFLA_BRPORT_PROXYARP
,
154 QEMU_IFLA_BRPORT_LEARNING_SYNC
,
155 QEMU_IFLA_BRPORT_PROXYARP_WIFI
,
156 QEMU_IFLA_BRPORT_ROOT_ID
,
157 QEMU_IFLA_BRPORT_BRIDGE_ID
,
158 QEMU_IFLA_BRPORT_DESIGNATED_PORT
,
159 QEMU_IFLA_BRPORT_DESIGNATED_COST
,
162 QEMU_IFLA_BRPORT_TOPOLOGY_CHANGE_ACK
,
163 QEMU_IFLA_BRPORT_CONFIG_PENDING
,
164 QEMU_IFLA_BRPORT_MESSAGE_AGE_TIMER
,
165 QEMU_IFLA_BRPORT_FORWARD_DELAY_TIMER
,
166 QEMU_IFLA_BRPORT_HOLD_TIMER
,
167 QEMU_IFLA_BRPORT_FLUSH
,
168 QEMU_IFLA_BRPORT_MULTICAST_ROUTER
,
169 QEMU_IFLA_BRPORT_PAD
,
170 QEMU_IFLA_BRPORT_MCAST_FLOOD
,
171 QEMU_IFLA_BRPORT_MCAST_TO_UCAST
,
172 QEMU_IFLA_BRPORT_VLAN_TUNNEL
,
173 QEMU_IFLA_BRPORT_BCAST_FLOOD
,
174 QEMU_IFLA_BRPORT_GROUP_FWD_MASK
,
175 QEMU_IFLA_BRPORT_NEIGH_SUPPRESS
,
176 QEMU_IFLA_BRPORT_ISOLATED
,
177 QEMU_IFLA_BRPORT_BACKUP_PORT
,
178 QEMU___IFLA_BRPORT_MAX
182 QEMU_IFLA_TUN_UNSPEC
,
187 QEMU_IFLA_TUN_VNET_HDR
,
188 QEMU_IFLA_TUN_PERSIST
,
189 QEMU_IFLA_TUN_MULTI_QUEUE
,
190 QEMU_IFLA_TUN_NUM_QUEUES
,
191 QEMU_IFLA_TUN_NUM_DISABLED_QUEUES
,
196 QEMU_IFLA_INFO_UNSPEC
,
199 QEMU_IFLA_INFO_XSTATS
,
200 QEMU_IFLA_INFO_SLAVE_KIND
,
201 QEMU_IFLA_INFO_SLAVE_DATA
,
202 QEMU___IFLA_INFO_MAX
,
206 QEMU_IFLA_INET_UNSPEC
,
208 QEMU___IFLA_INET_MAX
,
212 QEMU_IFLA_INET6_UNSPEC
,
213 QEMU_IFLA_INET6_FLAGS
,
214 QEMU_IFLA_INET6_CONF
,
215 QEMU_IFLA_INET6_STATS
,
216 QEMU_IFLA_INET6_MCAST
,
217 QEMU_IFLA_INET6_CACHEINFO
,
218 QEMU_IFLA_INET6_ICMP6STATS
,
219 QEMU_IFLA_INET6_TOKEN
,
220 QEMU_IFLA_INET6_ADDR_GEN_MODE
,
221 QEMU___IFLA_INET6_MAX
225 QEMU_IFLA_XDP_UNSPEC
,
227 QEMU_IFLA_XDP_ATTACHED
,
229 QEMU_IFLA_XDP_PROG_ID
,
244 QEMU_RTA_PROTOINFO
, /* no longer used */
247 QEMU_RTA_SESSION
, /* no longer used */
248 QEMU_RTA_MP_ALGO
, /* no longer used */
260 QEMU_RTA_TTL_PROPAGATE
,
267 TargetFdTrans
**target_fd_trans
;
268 unsigned int target_fd_max
;
270 static void tswap_nlmsghdr(struct nlmsghdr
*nlh
)
272 nlh
->nlmsg_len
= tswap32(nlh
->nlmsg_len
);
273 nlh
->nlmsg_type
= tswap16(nlh
->nlmsg_type
);
274 nlh
->nlmsg_flags
= tswap16(nlh
->nlmsg_flags
);
275 nlh
->nlmsg_seq
= tswap32(nlh
->nlmsg_seq
);
276 nlh
->nlmsg_pid
= tswap32(nlh
->nlmsg_pid
);
279 static abi_long
host_to_target_for_each_nlmsg(struct nlmsghdr
*nlh
,
281 abi_long (*host_to_target_nlmsg
)
285 uint32_t aligned_nlmsg_len
;
288 while (len
> sizeof(struct nlmsghdr
)) {
290 nlmsg_len
= nlh
->nlmsg_len
;
291 if (nlmsg_len
< sizeof(struct nlmsghdr
) ||
296 switch (nlh
->nlmsg_type
) {
304 struct nlmsgerr
*e
= NLMSG_DATA(nlh
);
305 e
->error
= tswap32(e
->error
);
306 tswap_nlmsghdr(&e
->msg
);
311 ret
= host_to_target_nlmsg(nlh
);
320 aligned_nlmsg_len
= NLMSG_ALIGN(nlmsg_len
);
321 if (aligned_nlmsg_len
>= len
) {
324 len
-= aligned_nlmsg_len
;
325 nlh
= (struct nlmsghdr
*)(((char*)nlh
) + aligned_nlmsg_len
);
330 static abi_long
target_to_host_for_each_nlmsg(struct nlmsghdr
*nlh
,
332 abi_long (*target_to_host_nlmsg
)
335 uint32_t aligned_nlmsg_len
;
338 while (len
> sizeof(struct nlmsghdr
)) {
339 if (tswap32(nlh
->nlmsg_len
) < sizeof(struct nlmsghdr
) ||
340 tswap32(nlh
->nlmsg_len
) > len
) {
344 switch (nlh
->nlmsg_type
) {
351 struct nlmsgerr
*e
= NLMSG_DATA(nlh
);
352 e
->error
= tswap32(e
->error
);
353 tswap_nlmsghdr(&e
->msg
);
357 ret
= target_to_host_nlmsg(nlh
);
363 aligned_nlmsg_len
= NLMSG_ALIGN(nlh
->nlmsg_len
);
364 if (aligned_nlmsg_len
>= len
) {
367 len
-= aligned_nlmsg_len
;
368 nlh
= (struct nlmsghdr
*)(((char *)nlh
) + aligned_nlmsg_len
);
373 #ifdef CONFIG_RTNETLINK
374 static abi_long
host_to_target_for_each_nlattr(struct nlattr
*nlattr
,
375 size_t len
, void *context
,
376 abi_long (*host_to_target_nlattr
)
380 unsigned short nla_len
;
381 unsigned short aligned_nla_len
;
384 while (len
> sizeof(struct nlattr
)) {
385 nla_len
= nlattr
->nla_len
;
386 if (nla_len
< sizeof(struct nlattr
) ||
390 ret
= host_to_target_nlattr(nlattr
, context
);
391 nlattr
->nla_len
= tswap16(nlattr
->nla_len
);
392 nlattr
->nla_type
= tswap16(nlattr
->nla_type
);
397 aligned_nla_len
= NLA_ALIGN(nla_len
);
398 if (aligned_nla_len
>= len
) {
401 len
-= aligned_nla_len
;
402 nlattr
= (struct nlattr
*)(((char *)nlattr
) + aligned_nla_len
);
407 static abi_long
host_to_target_for_each_rtattr(struct rtattr
*rtattr
,
409 abi_long (*host_to_target_rtattr
)
412 unsigned short rta_len
;
413 unsigned short aligned_rta_len
;
416 while (len
> sizeof(struct rtattr
)) {
417 rta_len
= rtattr
->rta_len
;
418 if (rta_len
< sizeof(struct rtattr
) ||
422 ret
= host_to_target_rtattr(rtattr
);
423 rtattr
->rta_len
= tswap16(rtattr
->rta_len
);
424 rtattr
->rta_type
= tswap16(rtattr
->rta_type
);
429 aligned_rta_len
= RTA_ALIGN(rta_len
);
430 if (aligned_rta_len
>= len
) {
433 len
-= aligned_rta_len
;
434 rtattr
= (struct rtattr
*)(((char *)rtattr
) + aligned_rta_len
);
439 #define NLA_DATA(nla) ((void *)((char *)(nla)) + NLA_HDRLEN)
441 static abi_long
host_to_target_data_bridge_nlattr(struct nlattr
*nlattr
,
448 switch (nlattr
->nla_type
) {
450 case QEMU_IFLA_BR_FDB_FLUSH
:
453 case QEMU_IFLA_BR_GROUP_ADDR
:
456 case QEMU_IFLA_BR_VLAN_FILTERING
:
457 case QEMU_IFLA_BR_TOPOLOGY_CHANGE
:
458 case QEMU_IFLA_BR_TOPOLOGY_CHANGE_DETECTED
:
459 case QEMU_IFLA_BR_MCAST_ROUTER
:
460 case QEMU_IFLA_BR_MCAST_SNOOPING
:
461 case QEMU_IFLA_BR_MCAST_QUERY_USE_IFADDR
:
462 case QEMU_IFLA_BR_MCAST_QUERIER
:
463 case QEMU_IFLA_BR_NF_CALL_IPTABLES
:
464 case QEMU_IFLA_BR_NF_CALL_IP6TABLES
:
465 case QEMU_IFLA_BR_NF_CALL_ARPTABLES
:
466 case QEMU_IFLA_BR_VLAN_STATS_ENABLED
:
467 case QEMU_IFLA_BR_MCAST_STATS_ENABLED
:
468 case QEMU_IFLA_BR_MCAST_IGMP_VERSION
:
469 case QEMU_IFLA_BR_MCAST_MLD_VERSION
:
470 case QEMU_IFLA_BR_VLAN_STATS_PER_PORT
:
473 case QEMU_IFLA_BR_PRIORITY
:
474 case QEMU_IFLA_BR_VLAN_PROTOCOL
:
475 case QEMU_IFLA_BR_GROUP_FWD_MASK
:
476 case QEMU_IFLA_BR_ROOT_PORT
:
477 case QEMU_IFLA_BR_VLAN_DEFAULT_PVID
:
478 u16
= NLA_DATA(nlattr
);
479 *u16
= tswap16(*u16
);
482 case QEMU_IFLA_BR_FORWARD_DELAY
:
483 case QEMU_IFLA_BR_HELLO_TIME
:
484 case QEMU_IFLA_BR_MAX_AGE
:
485 case QEMU_IFLA_BR_AGEING_TIME
:
486 case QEMU_IFLA_BR_STP_STATE
:
487 case QEMU_IFLA_BR_ROOT_PATH_COST
:
488 case QEMU_IFLA_BR_MCAST_HASH_ELASTICITY
:
489 case QEMU_IFLA_BR_MCAST_HASH_MAX
:
490 case QEMU_IFLA_BR_MCAST_LAST_MEMBER_CNT
:
491 case QEMU_IFLA_BR_MCAST_STARTUP_QUERY_CNT
:
492 u32
= NLA_DATA(nlattr
);
493 *u32
= tswap32(*u32
);
496 case QEMU_IFLA_BR_HELLO_TIMER
:
497 case QEMU_IFLA_BR_TCN_TIMER
:
498 case QEMU_IFLA_BR_GC_TIMER
:
499 case QEMU_IFLA_BR_TOPOLOGY_CHANGE_TIMER
:
500 case QEMU_IFLA_BR_MCAST_LAST_MEMBER_INTVL
:
501 case QEMU_IFLA_BR_MCAST_MEMBERSHIP_INTVL
:
502 case QEMU_IFLA_BR_MCAST_QUERIER_INTVL
:
503 case QEMU_IFLA_BR_MCAST_QUERY_INTVL
:
504 case QEMU_IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
:
505 case QEMU_IFLA_BR_MCAST_STARTUP_QUERY_INTVL
:
506 u64
= NLA_DATA(nlattr
);
507 *u64
= tswap64(*u64
);
509 /* ifla_bridge_id: uin8_t[] */
510 case QEMU_IFLA_BR_ROOT_ID
:
511 case QEMU_IFLA_BR_BRIDGE_ID
:
513 /* br_boolopt_multi { uint32_t, uint32_t } */
514 case QEMU_IFLA_BR_MULTI_BOOLOPT
:
515 u32
= NLA_DATA(nlattr
);
516 u32
[0] = tswap32(u32
[0]); /* optval */
517 u32
[1] = tswap32(u32
[1]); /* optmask */
520 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_BR type %d\n",
527 static abi_long
host_to_target_slave_data_bridge_nlattr(struct nlattr
*nlattr
,
534 switch (nlattr
->nla_type
) {
536 case QEMU_IFLA_BRPORT_STATE
:
537 case QEMU_IFLA_BRPORT_MODE
:
538 case QEMU_IFLA_BRPORT_GUARD
:
539 case QEMU_IFLA_BRPORT_PROTECT
:
540 case QEMU_IFLA_BRPORT_FAST_LEAVE
:
541 case QEMU_IFLA_BRPORT_LEARNING
:
542 case QEMU_IFLA_BRPORT_UNICAST_FLOOD
:
543 case QEMU_IFLA_BRPORT_PROXYARP
:
544 case QEMU_IFLA_BRPORT_LEARNING_SYNC
:
545 case QEMU_IFLA_BRPORT_PROXYARP_WIFI
:
546 case QEMU_IFLA_BRPORT_TOPOLOGY_CHANGE_ACK
:
547 case QEMU_IFLA_BRPORT_CONFIG_PENDING
:
548 case QEMU_IFLA_BRPORT_MULTICAST_ROUTER
:
549 case QEMU_IFLA_BRPORT_MCAST_FLOOD
:
550 case QEMU_IFLA_BRPORT_MCAST_TO_UCAST
:
551 case QEMU_IFLA_BRPORT_VLAN_TUNNEL
:
552 case QEMU_IFLA_BRPORT_BCAST_FLOOD
:
553 case QEMU_IFLA_BRPORT_NEIGH_SUPPRESS
:
554 case QEMU_IFLA_BRPORT_ISOLATED
:
557 case QEMU_IFLA_BRPORT_PRIORITY
:
558 case QEMU_IFLA_BRPORT_DESIGNATED_PORT
:
559 case QEMU_IFLA_BRPORT_DESIGNATED_COST
:
560 case QEMU_IFLA_BRPORT_ID
:
561 case QEMU_IFLA_BRPORT_NO
:
562 case QEMU_IFLA_BRPORT_GROUP_FWD_MASK
:
563 u16
= NLA_DATA(nlattr
);
564 *u16
= tswap16(*u16
);
567 case QEMU_IFLA_BRPORT_COST
:
568 case QEMU_IFLA_BRPORT_BACKUP_PORT
:
569 u32
= NLA_DATA(nlattr
);
570 *u32
= tswap32(*u32
);
573 case QEMU_IFLA_BRPORT_MESSAGE_AGE_TIMER
:
574 case QEMU_IFLA_BRPORT_FORWARD_DELAY_TIMER
:
575 case QEMU_IFLA_BRPORT_HOLD_TIMER
:
576 u64
= NLA_DATA(nlattr
);
577 *u64
= tswap64(*u64
);
579 /* ifla_bridge_id: uint8_t[] */
580 case QEMU_IFLA_BRPORT_ROOT_ID
:
581 case QEMU_IFLA_BRPORT_BRIDGE_ID
:
584 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_BRPORT type %d\n",
591 static abi_long
host_to_target_data_tun_nlattr(struct nlattr
*nlattr
,
596 switch (nlattr
->nla_type
) {
598 case QEMU_IFLA_TUN_TYPE
:
599 case QEMU_IFLA_TUN_PI
:
600 case QEMU_IFLA_TUN_VNET_HDR
:
601 case QEMU_IFLA_TUN_PERSIST
:
602 case QEMU_IFLA_TUN_MULTI_QUEUE
:
605 case QEMU_IFLA_TUN_NUM_QUEUES
:
606 case QEMU_IFLA_TUN_NUM_DISABLED_QUEUES
:
607 case QEMU_IFLA_TUN_OWNER
:
608 case QEMU_IFLA_TUN_GROUP
:
609 u32
= NLA_DATA(nlattr
);
610 *u32
= tswap32(*u32
);
613 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_TUN type %d\n",
620 struct linkinfo_context
{
627 static abi_long
host_to_target_data_linkinfo_nlattr(struct nlattr
*nlattr
,
630 struct linkinfo_context
*li_context
= context
;
632 switch (nlattr
->nla_type
) {
634 case QEMU_IFLA_INFO_KIND
:
635 li_context
->name
= NLA_DATA(nlattr
);
636 li_context
->len
= nlattr
->nla_len
- NLA_HDRLEN
;
638 case QEMU_IFLA_INFO_SLAVE_KIND
:
639 li_context
->slave_name
= NLA_DATA(nlattr
);
640 li_context
->slave_len
= nlattr
->nla_len
- NLA_HDRLEN
;
643 case QEMU_IFLA_INFO_XSTATS
:
644 /* FIXME: only used by CAN */
647 case QEMU_IFLA_INFO_DATA
:
648 if (strncmp(li_context
->name
, "bridge",
649 li_context
->len
) == 0) {
650 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
),
653 host_to_target_data_bridge_nlattr
);
654 } else if (strncmp(li_context
->name
, "tun",
655 li_context
->len
) == 0) {
656 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
),
659 host_to_target_data_tun_nlattr
);
661 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_INFO_KIND %s\n",
665 case QEMU_IFLA_INFO_SLAVE_DATA
:
666 if (strncmp(li_context
->slave_name
, "bridge",
667 li_context
->slave_len
) == 0) {
668 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
),
671 host_to_target_slave_data_bridge_nlattr
);
673 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_INFO_SLAVE_KIND %s\n",
674 li_context
->slave_name
);
678 qemu_log_mask(LOG_UNIMP
, "Unknown host QEMU_IFLA_INFO type: %d\n",
686 static abi_long
host_to_target_data_inet_nlattr(struct nlattr
*nlattr
,
692 switch (nlattr
->nla_type
) {
693 case QEMU_IFLA_INET_CONF
:
694 u32
= NLA_DATA(nlattr
);
695 for (i
= 0; i
< (nlattr
->nla_len
- NLA_HDRLEN
) / sizeof(*u32
);
697 u32
[i
] = tswap32(u32
[i
]);
701 qemu_log_mask(LOG_UNIMP
, "Unknown host AF_INET type: %d\n",
707 static abi_long
host_to_target_data_inet6_nlattr(struct nlattr
*nlattr
,
712 struct ifla_cacheinfo
*ci
;
715 switch (nlattr
->nla_type
) {
717 case QEMU_IFLA_INET6_TOKEN
:
720 case QEMU_IFLA_INET6_ADDR_GEN_MODE
:
723 case QEMU_IFLA_INET6_FLAGS
:
724 u32
= NLA_DATA(nlattr
);
725 *u32
= tswap32(*u32
);
728 case QEMU_IFLA_INET6_CONF
:
729 u32
= NLA_DATA(nlattr
);
730 for (i
= 0; i
< (nlattr
->nla_len
- NLA_HDRLEN
) / sizeof(*u32
);
732 u32
[i
] = tswap32(u32
[i
]);
736 case QEMU_IFLA_INET6_CACHEINFO
:
737 ci
= NLA_DATA(nlattr
);
738 ci
->max_reasm_len
= tswap32(ci
->max_reasm_len
);
739 ci
->tstamp
= tswap32(ci
->tstamp
);
740 ci
->reachable_time
= tswap32(ci
->reachable_time
);
741 ci
->retrans_time
= tswap32(ci
->retrans_time
);
744 case QEMU_IFLA_INET6_STATS
:
745 case QEMU_IFLA_INET6_ICMP6STATS
:
746 u64
= NLA_DATA(nlattr
);
747 for (i
= 0; i
< (nlattr
->nla_len
- NLA_HDRLEN
) / sizeof(*u64
);
749 u64
[i
] = tswap64(u64
[i
]);
753 qemu_log_mask(LOG_UNIMP
, "Unknown host AF_INET6 type: %d\n",
759 static abi_long
host_to_target_data_spec_nlattr(struct nlattr
*nlattr
,
762 switch (nlattr
->nla_type
) {
764 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
), nlattr
->nla_len
,
766 host_to_target_data_inet_nlattr
);
768 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
), nlattr
->nla_len
,
770 host_to_target_data_inet6_nlattr
);
772 qemu_log_mask(LOG_UNIMP
, "Unknown host AF_SPEC type: %d\n",
779 static abi_long
host_to_target_data_xdp_nlattr(struct nlattr
*nlattr
,
784 switch (nlattr
->nla_type
) {
786 case QEMU_IFLA_XDP_ATTACHED
:
789 case QEMU_IFLA_XDP_PROG_ID
:
790 u32
= NLA_DATA(nlattr
);
791 *u32
= tswap32(*u32
);
795 LOG_UNIMP
, "Unknown host XDP type: %d\n", nlattr
->nla_type
);
801 static abi_long
host_to_target_data_link_rtattr(struct rtattr
*rtattr
)
804 struct rtnl_link_stats
*st
;
805 struct rtnl_link_stats64
*st64
;
806 struct rtnl_link_ifmap
*map
;
807 struct linkinfo_context li_context
;
809 switch (rtattr
->rta_type
) {
811 case QEMU_IFLA_ADDRESS
:
812 case QEMU_IFLA_BROADCAST
:
813 case QEMU_IFLA_PERM_ADDRESS
:
815 case QEMU_IFLA_IFNAME
:
816 case QEMU_IFLA_QDISC
:
819 case QEMU_IFLA_OPERSTATE
:
820 case QEMU_IFLA_LINKMODE
:
821 case QEMU_IFLA_CARRIER
:
822 case QEMU_IFLA_PROTO_DOWN
:
827 case QEMU_IFLA_WEIGHT
:
828 case QEMU_IFLA_TXQLEN
:
829 case QEMU_IFLA_CARRIER_CHANGES
:
830 case QEMU_IFLA_NUM_RX_QUEUES
:
831 case QEMU_IFLA_NUM_TX_QUEUES
:
832 case QEMU_IFLA_PROMISCUITY
:
833 case QEMU_IFLA_EXT_MASK
:
834 case QEMU_IFLA_LINK_NETNSID
:
835 case QEMU_IFLA_GROUP
:
836 case QEMU_IFLA_MASTER
:
837 case QEMU_IFLA_NUM_VF
:
838 case QEMU_IFLA_GSO_MAX_SEGS
:
839 case QEMU_IFLA_GSO_MAX_SIZE
:
840 case QEMU_IFLA_CARRIER_UP_COUNT
:
841 case QEMU_IFLA_CARRIER_DOWN_COUNT
:
842 case QEMU_IFLA_MIN_MTU
:
843 case QEMU_IFLA_MAX_MTU
:
844 u32
= RTA_DATA(rtattr
);
845 *u32
= tswap32(*u32
);
847 /* struct rtnl_link_stats */
848 case QEMU_IFLA_STATS
:
849 st
= RTA_DATA(rtattr
);
850 st
->rx_packets
= tswap32(st
->rx_packets
);
851 st
->tx_packets
= tswap32(st
->tx_packets
);
852 st
->rx_bytes
= tswap32(st
->rx_bytes
);
853 st
->tx_bytes
= tswap32(st
->tx_bytes
);
854 st
->rx_errors
= tswap32(st
->rx_errors
);
855 st
->tx_errors
= tswap32(st
->tx_errors
);
856 st
->rx_dropped
= tswap32(st
->rx_dropped
);
857 st
->tx_dropped
= tswap32(st
->tx_dropped
);
858 st
->multicast
= tswap32(st
->multicast
);
859 st
->collisions
= tswap32(st
->collisions
);
861 /* detailed rx_errors: */
862 st
->rx_length_errors
= tswap32(st
->rx_length_errors
);
863 st
->rx_over_errors
= tswap32(st
->rx_over_errors
);
864 st
->rx_crc_errors
= tswap32(st
->rx_crc_errors
);
865 st
->rx_frame_errors
= tswap32(st
->rx_frame_errors
);
866 st
->rx_fifo_errors
= tswap32(st
->rx_fifo_errors
);
867 st
->rx_missed_errors
= tswap32(st
->rx_missed_errors
);
869 /* detailed tx_errors */
870 st
->tx_aborted_errors
= tswap32(st
->tx_aborted_errors
);
871 st
->tx_carrier_errors
= tswap32(st
->tx_carrier_errors
);
872 st
->tx_fifo_errors
= tswap32(st
->tx_fifo_errors
);
873 st
->tx_heartbeat_errors
= tswap32(st
->tx_heartbeat_errors
);
874 st
->tx_window_errors
= tswap32(st
->tx_window_errors
);
877 st
->rx_compressed
= tswap32(st
->rx_compressed
);
878 st
->tx_compressed
= tswap32(st
->tx_compressed
);
880 /* struct rtnl_link_stats64 */
881 case QEMU_IFLA_STATS64
:
882 st64
= RTA_DATA(rtattr
);
883 st64
->rx_packets
= tswap64(st64
->rx_packets
);
884 st64
->tx_packets
= tswap64(st64
->tx_packets
);
885 st64
->rx_bytes
= tswap64(st64
->rx_bytes
);
886 st64
->tx_bytes
= tswap64(st64
->tx_bytes
);
887 st64
->rx_errors
= tswap64(st64
->rx_errors
);
888 st64
->tx_errors
= tswap64(st64
->tx_errors
);
889 st64
->rx_dropped
= tswap64(st64
->rx_dropped
);
890 st64
->tx_dropped
= tswap64(st64
->tx_dropped
);
891 st64
->multicast
= tswap64(st64
->multicast
);
892 st64
->collisions
= tswap64(st64
->collisions
);
894 /* detailed rx_errors: */
895 st64
->rx_length_errors
= tswap64(st64
->rx_length_errors
);
896 st64
->rx_over_errors
= tswap64(st64
->rx_over_errors
);
897 st64
->rx_crc_errors
= tswap64(st64
->rx_crc_errors
);
898 st64
->rx_frame_errors
= tswap64(st64
->rx_frame_errors
);
899 st64
->rx_fifo_errors
= tswap64(st64
->rx_fifo_errors
);
900 st64
->rx_missed_errors
= tswap64(st64
->rx_missed_errors
);
902 /* detailed tx_errors */
903 st64
->tx_aborted_errors
= tswap64(st64
->tx_aborted_errors
);
904 st64
->tx_carrier_errors
= tswap64(st64
->tx_carrier_errors
);
905 st64
->tx_fifo_errors
= tswap64(st64
->tx_fifo_errors
);
906 st64
->tx_heartbeat_errors
= tswap64(st64
->tx_heartbeat_errors
);
907 st64
->tx_window_errors
= tswap64(st64
->tx_window_errors
);
910 st64
->rx_compressed
= tswap64(st64
->rx_compressed
);
911 st64
->tx_compressed
= tswap64(st64
->tx_compressed
);
913 /* struct rtnl_link_ifmap */
915 map
= RTA_DATA(rtattr
);
916 map
->mem_start
= tswap64(map
->mem_start
);
917 map
->mem_end
= tswap64(map
->mem_end
);
918 map
->base_addr
= tswap64(map
->base_addr
);
919 map
->irq
= tswap16(map
->irq
);
922 case QEMU_IFLA_LINKINFO
:
923 memset(&li_context
, 0, sizeof(li_context
));
924 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
926 host_to_target_data_linkinfo_nlattr
);
927 case QEMU_IFLA_AF_SPEC
:
928 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
930 host_to_target_data_spec_nlattr
);
932 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
934 host_to_target_data_xdp_nlattr
);
936 qemu_log_mask(LOG_UNIMP
, "Unknown host QEMU_IFLA type: %d\n",
943 static abi_long
host_to_target_data_addr_rtattr(struct rtattr
*rtattr
)
946 struct ifa_cacheinfo
*ci
;
948 switch (rtattr
->rta_type
) {
949 /* binary: depends on family type */
959 u32
= RTA_DATA(rtattr
);
960 *u32
= tswap32(*u32
);
962 /* struct ifa_cacheinfo */
964 ci
= RTA_DATA(rtattr
);
965 ci
->ifa_prefered
= tswap32(ci
->ifa_prefered
);
966 ci
->ifa_valid
= tswap32(ci
->ifa_valid
);
967 ci
->cstamp
= tswap32(ci
->cstamp
);
968 ci
->tstamp
= tswap32(ci
->tstamp
);
972 LOG_UNIMP
, "Unknown host IFA type: %d\n", rtattr
->rta_type
);
978 static abi_long
host_to_target_data_route_rtattr(struct rtattr
*rtattr
)
981 struct rta_cacheinfo
*ci
;
983 switch (rtattr
->rta_type
) {
984 /* binary: depends on family type */
985 case QEMU_RTA_GATEWAY
:
987 case QEMU_RTA_PREFSRC
:
993 case QEMU_RTA_PRIORITY
:
996 u32
= RTA_DATA(rtattr
);
997 *u32
= tswap32(*u32
);
999 /* struct rta_cacheinfo */
1000 case QEMU_RTA_CACHEINFO
:
1001 ci
= RTA_DATA(rtattr
);
1002 ci
->rta_clntref
= tswap32(ci
->rta_clntref
);
1003 ci
->rta_lastuse
= tswap32(ci
->rta_lastuse
);
1004 ci
->rta_expires
= tswap32(ci
->rta_expires
);
1005 ci
->rta_error
= tswap32(ci
->rta_error
);
1006 ci
->rta_used
= tswap32(ci
->rta_used
);
1007 #if defined(RTNETLINK_HAVE_PEERINFO)
1008 ci
->rta_id
= tswap32(ci
->rta_id
);
1009 ci
->rta_ts
= tswap32(ci
->rta_ts
);
1010 ci
->rta_tsage
= tswap32(ci
->rta_tsage
);
1015 LOG_UNIMP
, "Unknown host RTA type: %d\n", rtattr
->rta_type
);
1021 static abi_long
host_to_target_link_rtattr(struct rtattr
*rtattr
,
1022 uint32_t rtattr_len
)
1024 return host_to_target_for_each_rtattr(rtattr
, rtattr_len
,
1025 host_to_target_data_link_rtattr
);
1028 static abi_long
host_to_target_addr_rtattr(struct rtattr
*rtattr
,
1029 uint32_t rtattr_len
)
1031 return host_to_target_for_each_rtattr(rtattr
, rtattr_len
,
1032 host_to_target_data_addr_rtattr
);
1035 static abi_long
host_to_target_route_rtattr(struct rtattr
*rtattr
,
1036 uint32_t rtattr_len
)
1038 return host_to_target_for_each_rtattr(rtattr
, rtattr_len
,
1039 host_to_target_data_route_rtattr
);
1042 static abi_long
host_to_target_data_route(struct nlmsghdr
*nlh
)
1045 struct ifinfomsg
*ifi
;
1046 struct ifaddrmsg
*ifa
;
1049 nlmsg_len
= nlh
->nlmsg_len
;
1050 switch (nlh
->nlmsg_type
) {
1054 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifi
))) {
1055 ifi
= NLMSG_DATA(nlh
);
1056 ifi
->ifi_type
= tswap16(ifi
->ifi_type
);
1057 ifi
->ifi_index
= tswap32(ifi
->ifi_index
);
1058 ifi
->ifi_flags
= tswap32(ifi
->ifi_flags
);
1059 ifi
->ifi_change
= tswap32(ifi
->ifi_change
);
1060 host_to_target_link_rtattr(IFLA_RTA(ifi
),
1061 nlmsg_len
- NLMSG_LENGTH(sizeof(*ifi
)));
1067 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifa
))) {
1068 ifa
= NLMSG_DATA(nlh
);
1069 ifa
->ifa_index
= tswap32(ifa
->ifa_index
);
1070 host_to_target_addr_rtattr(IFA_RTA(ifa
),
1071 nlmsg_len
- NLMSG_LENGTH(sizeof(*ifa
)));
1077 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*rtm
))) {
1078 rtm
= NLMSG_DATA(nlh
);
1079 rtm
->rtm_flags
= tswap32(rtm
->rtm_flags
);
1080 host_to_target_route_rtattr(RTM_RTA(rtm
),
1081 nlmsg_len
- NLMSG_LENGTH(sizeof(*rtm
)));
1085 return -TARGET_EINVAL
;
1090 static inline abi_long
host_to_target_nlmsg_route(struct nlmsghdr
*nlh
,
1093 return host_to_target_for_each_nlmsg(nlh
, len
, host_to_target_data_route
);
1096 static abi_long
target_to_host_for_each_rtattr(struct rtattr
*rtattr
,
1098 abi_long (*target_to_host_rtattr
)
1101 unsigned short aligned_rta_len
;
1104 while (len
>= sizeof(struct rtattr
)) {
1105 if (tswap16(rtattr
->rta_len
) < sizeof(struct rtattr
) ||
1106 tswap16(rtattr
->rta_len
) > len
) {
1109 rtattr
->rta_len
= tswap16(rtattr
->rta_len
);
1110 rtattr
->rta_type
= tswap16(rtattr
->rta_type
);
1111 ret
= target_to_host_rtattr(rtattr
);
1116 aligned_rta_len
= RTA_ALIGN(rtattr
->rta_len
);
1117 if (aligned_rta_len
>= len
) {
1120 len
-= aligned_rta_len
;
1121 rtattr
= (struct rtattr
*)(((char *)rtattr
) + aligned_rta_len
);
1126 static abi_long
target_to_host_data_link_rtattr(struct rtattr
*rtattr
)
1128 switch (rtattr
->rta_type
) {
1130 qemu_log_mask(LOG_UNIMP
, "Unknown target QEMU_IFLA type: %d\n",
1137 static abi_long
target_to_host_data_addr_rtattr(struct rtattr
*rtattr
)
1139 switch (rtattr
->rta_type
) {
1140 /* binary: depends on family type */
1145 qemu_log_mask(LOG_UNIMP
, "Unknown target IFA type: %d\n",
1152 static abi_long
target_to_host_data_route_rtattr(struct rtattr
*rtattr
)
1155 switch (rtattr
->rta_type
) {
1156 /* binary: depends on family type */
1159 case QEMU_RTA_GATEWAY
:
1162 case QEMU_RTA_PRIORITY
:
1164 u32
= RTA_DATA(rtattr
);
1165 *u32
= tswap32(*u32
);
1168 qemu_log_mask(LOG_UNIMP
, "Unknown target RTA type: %d\n",
1175 static void target_to_host_link_rtattr(struct rtattr
*rtattr
,
1176 uint32_t rtattr_len
)
1178 target_to_host_for_each_rtattr(rtattr
, rtattr_len
,
1179 target_to_host_data_link_rtattr
);
1182 static void target_to_host_addr_rtattr(struct rtattr
*rtattr
,
1183 uint32_t rtattr_len
)
1185 target_to_host_for_each_rtattr(rtattr
, rtattr_len
,
1186 target_to_host_data_addr_rtattr
);
1189 static void target_to_host_route_rtattr(struct rtattr
*rtattr
,
1190 uint32_t rtattr_len
)
1192 target_to_host_for_each_rtattr(rtattr
, rtattr_len
,
1193 target_to_host_data_route_rtattr
);
1196 static abi_long
target_to_host_data_route(struct nlmsghdr
*nlh
)
1198 struct ifinfomsg
*ifi
;
1199 struct ifaddrmsg
*ifa
;
1202 switch (nlh
->nlmsg_type
) {
1208 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifi
))) {
1209 ifi
= NLMSG_DATA(nlh
);
1210 ifi
->ifi_type
= tswap16(ifi
->ifi_type
);
1211 ifi
->ifi_index
= tswap32(ifi
->ifi_index
);
1212 ifi
->ifi_flags
= tswap32(ifi
->ifi_flags
);
1213 ifi
->ifi_change
= tswap32(ifi
->ifi_change
);
1214 target_to_host_link_rtattr(IFLA_RTA(ifi
), nlh
->nlmsg_len
-
1215 NLMSG_LENGTH(sizeof(*ifi
)));
1221 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifa
))) {
1222 ifa
= NLMSG_DATA(nlh
);
1223 ifa
->ifa_index
= tswap32(ifa
->ifa_index
);
1224 target_to_host_addr_rtattr(IFA_RTA(ifa
), nlh
->nlmsg_len
-
1225 NLMSG_LENGTH(sizeof(*ifa
)));
1232 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*rtm
))) {
1233 rtm
= NLMSG_DATA(nlh
);
1234 rtm
->rtm_flags
= tswap32(rtm
->rtm_flags
);
1235 target_to_host_route_rtattr(RTM_RTA(rtm
), nlh
->nlmsg_len
-
1236 NLMSG_LENGTH(sizeof(*rtm
)));
1240 return -TARGET_EOPNOTSUPP
;
1245 static abi_long
target_to_host_nlmsg_route(struct nlmsghdr
*nlh
, size_t len
)
1247 return target_to_host_for_each_nlmsg(nlh
, len
, target_to_host_data_route
);
1249 #endif /* CONFIG_RTNETLINK */
1251 static abi_long
host_to_target_data_audit(struct nlmsghdr
*nlh
)
1253 switch (nlh
->nlmsg_type
) {
1255 qemu_log_mask(LOG_UNIMP
, "Unknown host audit message type %d\n",
1257 return -TARGET_EINVAL
;
1262 static inline abi_long
host_to_target_nlmsg_audit(struct nlmsghdr
*nlh
,
1265 return host_to_target_for_each_nlmsg(nlh
, len
, host_to_target_data_audit
);
1268 static abi_long
target_to_host_data_audit(struct nlmsghdr
*nlh
)
1270 switch (nlh
->nlmsg_type
) {
1272 case AUDIT_FIRST_USER_MSG
... AUDIT_LAST_USER_MSG
:
1273 case AUDIT_FIRST_USER_MSG2
... AUDIT_LAST_USER_MSG2
:
1276 qemu_log_mask(LOG_UNIMP
, "Unknown target audit message type %d\n",
1278 return -TARGET_EINVAL
;
1284 static abi_long
target_to_host_nlmsg_audit(struct nlmsghdr
*nlh
, size_t len
)
1286 return target_to_host_for_each_nlmsg(nlh
, len
, target_to_host_data_audit
);
1289 static abi_long
packet_target_to_host_sockaddr(void *host_addr
,
1290 abi_ulong target_addr
,
1293 struct sockaddr
*addr
= host_addr
;
1294 struct target_sockaddr
*target_saddr
;
1296 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1297 if (!target_saddr
) {
1298 return -TARGET_EFAULT
;
1301 memcpy(addr
, target_saddr
, len
);
1302 addr
->sa_family
= tswap16(target_saddr
->sa_family
);
1303 /* spkt_protocol is big-endian */
1305 unlock_user(target_saddr
, target_addr
, 0);
1309 TargetFdTrans target_packet_trans
= {
1310 .target_to_host_addr
= packet_target_to_host_sockaddr
,
1313 #ifdef CONFIG_RTNETLINK
1314 static abi_long
netlink_route_target_to_host(void *buf
, size_t len
)
1318 ret
= target_to_host_nlmsg_route(buf
, len
);
1326 static abi_long
netlink_route_host_to_target(void *buf
, size_t len
)
1330 ret
= host_to_target_nlmsg_route(buf
, len
);
1338 TargetFdTrans target_netlink_route_trans
= {
1339 .target_to_host_data
= netlink_route_target_to_host
,
1340 .host_to_target_data
= netlink_route_host_to_target
,
1342 #endif /* CONFIG_RTNETLINK */
1344 static abi_long
netlink_audit_target_to_host(void *buf
, size_t len
)
1348 ret
= target_to_host_nlmsg_audit(buf
, len
);
1356 static abi_long
netlink_audit_host_to_target(void *buf
, size_t len
)
1360 ret
= host_to_target_nlmsg_audit(buf
, len
);
1368 TargetFdTrans target_netlink_audit_trans
= {
1369 .target_to_host_data
= netlink_audit_target_to_host
,
1370 .host_to_target_data
= netlink_audit_host_to_target
,
1373 /* signalfd siginfo conversion */
1376 host_to_target_signalfd_siginfo(struct signalfd_siginfo
*tinfo
,
1377 const struct signalfd_siginfo
*info
)
1379 int sig
= host_to_target_signal(info
->ssi_signo
);
1381 /* linux/signalfd.h defines a ssi_addr_lsb
1382 * not defined in sys/signalfd.h but used by some kernels
1385 #ifdef BUS_MCEERR_AO
1386 if (tinfo
->ssi_signo
== SIGBUS
&&
1387 (tinfo
->ssi_code
== BUS_MCEERR_AR
||
1388 tinfo
->ssi_code
== BUS_MCEERR_AO
)) {
1389 uint16_t *ssi_addr_lsb
= (uint16_t *)(&info
->ssi_addr
+ 1);
1390 uint16_t *tssi_addr_lsb
= (uint16_t *)(&tinfo
->ssi_addr
+ 1);
1391 *tssi_addr_lsb
= tswap16(*ssi_addr_lsb
);
1395 tinfo
->ssi_signo
= tswap32(sig
);
1396 tinfo
->ssi_errno
= tswap32(tinfo
->ssi_errno
);
1397 tinfo
->ssi_code
= tswap32(info
->ssi_code
);
1398 tinfo
->ssi_pid
= tswap32(info
->ssi_pid
);
1399 tinfo
->ssi_uid
= tswap32(info
->ssi_uid
);
1400 tinfo
->ssi_fd
= tswap32(info
->ssi_fd
);
1401 tinfo
->ssi_tid
= tswap32(info
->ssi_tid
);
1402 tinfo
->ssi_band
= tswap32(info
->ssi_band
);
1403 tinfo
->ssi_overrun
= tswap32(info
->ssi_overrun
);
1404 tinfo
->ssi_trapno
= tswap32(info
->ssi_trapno
);
1405 tinfo
->ssi_status
= tswap32(info
->ssi_status
);
1406 tinfo
->ssi_int
= tswap32(info
->ssi_int
);
1407 tinfo
->ssi_ptr
= tswap64(info
->ssi_ptr
);
1408 tinfo
->ssi_utime
= tswap64(info
->ssi_utime
);
1409 tinfo
->ssi_stime
= tswap64(info
->ssi_stime
);
1410 tinfo
->ssi_addr
= tswap64(info
->ssi_addr
);
1413 static abi_long
host_to_target_data_signalfd(void *buf
, size_t len
)
1417 for (i
= 0; i
< len
; i
+= sizeof(struct signalfd_siginfo
)) {
1418 host_to_target_signalfd_siginfo(buf
+ i
, buf
+ i
);
1424 TargetFdTrans target_signalfd_trans
= {
1425 .host_to_target_data
= host_to_target_data_signalfd
,
1428 static abi_long
swap_data_eventfd(void *buf
, size_t len
)
1430 uint64_t *counter
= buf
;
1433 if (len
< sizeof(uint64_t)) {
1437 for (i
= 0; i
< len
; i
+= sizeof(uint64_t)) {
1438 *counter
= tswap64(*counter
);
1445 TargetFdTrans target_eventfd_trans
= {
1446 .host_to_target_data
= swap_data_eventfd
,
1447 .target_to_host_data
= swap_data_eventfd
,
1450 #if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \
1451 (defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \
1452 defined(__NR_inotify_init1))
1453 static abi_long
host_to_target_data_inotify(void *buf
, size_t len
)
1455 struct inotify_event
*ev
;
1459 for (i
= 0; i
< len
; i
+= sizeof(struct inotify_event
) + name_len
) {
1460 ev
= (struct inotify_event
*)((char *)buf
+ i
);
1463 ev
->wd
= tswap32(ev
->wd
);
1464 ev
->mask
= tswap32(ev
->mask
);
1465 ev
->cookie
= tswap32(ev
->cookie
);
1466 ev
->len
= tswap32(name_len
);
1472 TargetFdTrans target_inotify_trans
= {
1473 .host_to_target_data
= host_to_target_data_inotify
,