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>
30 #include "user-internals.h"
32 #include "signal-common.h"
36 QEMU_IFLA_BR_FORWARD_DELAY
,
37 QEMU_IFLA_BR_HELLO_TIME
,
39 QEMU_IFLA_BR_AGEING_TIME
,
40 QEMU_IFLA_BR_STP_STATE
,
41 QEMU_IFLA_BR_PRIORITY
,
42 QEMU_IFLA_BR_VLAN_FILTERING
,
43 QEMU_IFLA_BR_VLAN_PROTOCOL
,
44 QEMU_IFLA_BR_GROUP_FWD_MASK
,
46 QEMU_IFLA_BR_BRIDGE_ID
,
47 QEMU_IFLA_BR_ROOT_PORT
,
48 QEMU_IFLA_BR_ROOT_PATH_COST
,
49 QEMU_IFLA_BR_TOPOLOGY_CHANGE
,
50 QEMU_IFLA_BR_TOPOLOGY_CHANGE_DETECTED
,
51 QEMU_IFLA_BR_HELLO_TIMER
,
52 QEMU_IFLA_BR_TCN_TIMER
,
53 QEMU_IFLA_BR_TOPOLOGY_CHANGE_TIMER
,
54 QEMU_IFLA_BR_GC_TIMER
,
55 QEMU_IFLA_BR_GROUP_ADDR
,
56 QEMU_IFLA_BR_FDB_FLUSH
,
57 QEMU_IFLA_BR_MCAST_ROUTER
,
58 QEMU_IFLA_BR_MCAST_SNOOPING
,
59 QEMU_IFLA_BR_MCAST_QUERY_USE_IFADDR
,
60 QEMU_IFLA_BR_MCAST_QUERIER
,
61 QEMU_IFLA_BR_MCAST_HASH_ELASTICITY
,
62 QEMU_IFLA_BR_MCAST_HASH_MAX
,
63 QEMU_IFLA_BR_MCAST_LAST_MEMBER_CNT
,
64 QEMU_IFLA_BR_MCAST_STARTUP_QUERY_CNT
,
65 QEMU_IFLA_BR_MCAST_LAST_MEMBER_INTVL
,
66 QEMU_IFLA_BR_MCAST_MEMBERSHIP_INTVL
,
67 QEMU_IFLA_BR_MCAST_QUERIER_INTVL
,
68 QEMU_IFLA_BR_MCAST_QUERY_INTVL
,
69 QEMU_IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
,
70 QEMU_IFLA_BR_MCAST_STARTUP_QUERY_INTVL
,
71 QEMU_IFLA_BR_NF_CALL_IPTABLES
,
72 QEMU_IFLA_BR_NF_CALL_IP6TABLES
,
73 QEMU_IFLA_BR_NF_CALL_ARPTABLES
,
74 QEMU_IFLA_BR_VLAN_DEFAULT_PVID
,
76 QEMU_IFLA_BR_VLAN_STATS_ENABLED
,
77 QEMU_IFLA_BR_MCAST_STATS_ENABLED
,
78 QEMU_IFLA_BR_MCAST_IGMP_VERSION
,
79 QEMU_IFLA_BR_MCAST_MLD_VERSION
,
80 QEMU_IFLA_BR_VLAN_STATS_PER_PORT
,
81 QEMU_IFLA_BR_MULTI_BOOLOPT
,
105 QEMU_IFLA_NET_NS_PID
,
108 QEMU_IFLA_VFINFO_LIST
,
116 QEMU_IFLA_PROMISCUITY
,
117 QEMU_IFLA_NUM_TX_QUEUES
,
118 QEMU_IFLA_NUM_RX_QUEUES
,
120 QEMU_IFLA_PHYS_PORT_ID
,
121 QEMU_IFLA_CARRIER_CHANGES
,
122 QEMU_IFLA_PHYS_SWITCH_ID
,
123 QEMU_IFLA_LINK_NETNSID
,
124 QEMU_IFLA_PHYS_PORT_NAME
,
125 QEMU_IFLA_PROTO_DOWN
,
126 QEMU_IFLA_GSO_MAX_SEGS
,
127 QEMU_IFLA_GSO_MAX_SIZE
,
131 QEMU_IFLA_NEW_NETNSID
,
132 QEMU_IFLA_IF_NETNSID
,
133 QEMU_IFLA_CARRIER_UP_COUNT
,
134 QEMU_IFLA_CARRIER_DOWN_COUNT
,
135 QEMU_IFLA_NEW_IFINDEX
,
139 QEMU_IFLA_ALT_IFNAME
,
140 QEMU_IFLA_PERM_ADDRESS
,
141 QEMU_IFLA_PROTO_DOWN_REASON
,
142 QEMU_IFLA_PARENT_DEV_NAME
,
143 QEMU_IFLA_PARENT_DEV_BUS_NAME
,
148 QEMU_IFLA_BRPORT_UNSPEC
,
149 QEMU_IFLA_BRPORT_STATE
,
150 QEMU_IFLA_BRPORT_PRIORITY
,
151 QEMU_IFLA_BRPORT_COST
,
152 QEMU_IFLA_BRPORT_MODE
,
153 QEMU_IFLA_BRPORT_GUARD
,
154 QEMU_IFLA_BRPORT_PROTECT
,
155 QEMU_IFLA_BRPORT_FAST_LEAVE
,
156 QEMU_IFLA_BRPORT_LEARNING
,
157 QEMU_IFLA_BRPORT_UNICAST_FLOOD
,
158 QEMU_IFLA_BRPORT_PROXYARP
,
159 QEMU_IFLA_BRPORT_LEARNING_SYNC
,
160 QEMU_IFLA_BRPORT_PROXYARP_WIFI
,
161 QEMU_IFLA_BRPORT_ROOT_ID
,
162 QEMU_IFLA_BRPORT_BRIDGE_ID
,
163 QEMU_IFLA_BRPORT_DESIGNATED_PORT
,
164 QEMU_IFLA_BRPORT_DESIGNATED_COST
,
167 QEMU_IFLA_BRPORT_TOPOLOGY_CHANGE_ACK
,
168 QEMU_IFLA_BRPORT_CONFIG_PENDING
,
169 QEMU_IFLA_BRPORT_MESSAGE_AGE_TIMER
,
170 QEMU_IFLA_BRPORT_FORWARD_DELAY_TIMER
,
171 QEMU_IFLA_BRPORT_HOLD_TIMER
,
172 QEMU_IFLA_BRPORT_FLUSH
,
173 QEMU_IFLA_BRPORT_MULTICAST_ROUTER
,
174 QEMU_IFLA_BRPORT_PAD
,
175 QEMU_IFLA_BRPORT_MCAST_FLOOD
,
176 QEMU_IFLA_BRPORT_MCAST_TO_UCAST
,
177 QEMU_IFLA_BRPORT_VLAN_TUNNEL
,
178 QEMU_IFLA_BRPORT_BCAST_FLOOD
,
179 QEMU_IFLA_BRPORT_GROUP_FWD_MASK
,
180 QEMU_IFLA_BRPORT_NEIGH_SUPPRESS
,
181 QEMU_IFLA_BRPORT_ISOLATED
,
182 QEMU_IFLA_BRPORT_BACKUP_PORT
,
183 QEMU_IFLA_BRPORT_MRP_RING_OPEN
,
184 QEMU_IFLA_BRPORT_MRP_IN_OPEN
,
185 QEMU_IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT
,
186 QEMU_IFLA_BRPORT_MCAST_EHT_HOSTS_CNT
,
187 QEMU___IFLA_BRPORT_MAX
191 QEMU_IFLA_TUN_UNSPEC
,
196 QEMU_IFLA_TUN_VNET_HDR
,
197 QEMU_IFLA_TUN_PERSIST
,
198 QEMU_IFLA_TUN_MULTI_QUEUE
,
199 QEMU_IFLA_TUN_NUM_QUEUES
,
200 QEMU_IFLA_TUN_NUM_DISABLED_QUEUES
,
205 QEMU_IFLA_INFO_UNSPEC
,
208 QEMU_IFLA_INFO_XSTATS
,
209 QEMU_IFLA_INFO_SLAVE_KIND
,
210 QEMU_IFLA_INFO_SLAVE_DATA
,
211 QEMU___IFLA_INFO_MAX
,
215 QEMU_IFLA_INET_UNSPEC
,
217 QEMU___IFLA_INET_MAX
,
221 QEMU_IFLA_INET6_UNSPEC
,
222 QEMU_IFLA_INET6_FLAGS
,
223 QEMU_IFLA_INET6_CONF
,
224 QEMU_IFLA_INET6_STATS
,
225 QEMU_IFLA_INET6_MCAST
,
226 QEMU_IFLA_INET6_CACHEINFO
,
227 QEMU_IFLA_INET6_ICMP6STATS
,
228 QEMU_IFLA_INET6_TOKEN
,
229 QEMU_IFLA_INET6_ADDR_GEN_MODE
,
230 QEMU___IFLA_INET6_MAX
234 QEMU_IFLA_XDP_UNSPEC
,
236 QEMU_IFLA_XDP_ATTACHED
,
238 QEMU_IFLA_XDP_PROG_ID
,
253 QEMU_RTA_PROTOINFO
, /* no longer used */
256 QEMU_RTA_SESSION
, /* no longer used */
257 QEMU_RTA_MP_ALGO
, /* no longer used */
269 QEMU_RTA_TTL_PROPAGATE
,
277 QEMU_IFLA_VF_STATS_RX_PACKETS
,
278 QEMU_IFLA_VF_STATS_TX_PACKETS
,
279 QEMU_IFLA_VF_STATS_RX_BYTES
,
280 QEMU_IFLA_VF_STATS_TX_BYTES
,
281 QEMU_IFLA_VF_STATS_BROADCAST
,
282 QEMU_IFLA_VF_STATS_MULTICAST
,
283 QEMU_IFLA_VF_STATS_PAD
,
284 QEMU_IFLA_VF_STATS_RX_DROPPED
,
285 QEMU_IFLA_VF_STATS_TX_DROPPED
,
286 QEMU__IFLA_VF_STATS_MAX
,
293 QEMU_IFLA_VF_TX_RATE
,
294 QEMU_IFLA_VF_SPOOFCHK
,
295 QEMU_IFLA_VF_LINK_STATE
,
297 QEMU_IFLA_VF_RSS_QUERY_EN
,
300 QEMU_IFLA_VF_IB_NODE_GUID
,
301 QEMU_IFLA_VF_IB_PORT_GUID
,
302 QEMU_IFLA_VF_VLAN_LIST
,
303 QEMU_IFLA_VF_BROADCAST
,
307 TargetFdTrans
**target_fd_trans
;
308 QemuMutex target_fd_trans_lock
;
309 unsigned int target_fd_max
;
311 static void tswap_nlmsghdr(struct nlmsghdr
*nlh
)
313 nlh
->nlmsg_len
= tswap32(nlh
->nlmsg_len
);
314 nlh
->nlmsg_type
= tswap16(nlh
->nlmsg_type
);
315 nlh
->nlmsg_flags
= tswap16(nlh
->nlmsg_flags
);
316 nlh
->nlmsg_seq
= tswap32(nlh
->nlmsg_seq
);
317 nlh
->nlmsg_pid
= tswap32(nlh
->nlmsg_pid
);
320 static abi_long
host_to_target_for_each_nlmsg(struct nlmsghdr
*nlh
,
322 abi_long (*host_to_target_nlmsg
)
326 uint32_t aligned_nlmsg_len
;
329 while (len
> sizeof(struct nlmsghdr
)) {
331 nlmsg_len
= nlh
->nlmsg_len
;
332 if (nlmsg_len
< sizeof(struct nlmsghdr
) ||
337 switch (nlh
->nlmsg_type
) {
345 struct nlmsgerr
*e
= NLMSG_DATA(nlh
);
346 e
->error
= tswap32(e
->error
);
347 tswap_nlmsghdr(&e
->msg
);
352 ret
= host_to_target_nlmsg(nlh
);
361 aligned_nlmsg_len
= NLMSG_ALIGN(nlmsg_len
);
362 if (aligned_nlmsg_len
>= len
) {
365 len
-= aligned_nlmsg_len
;
366 nlh
= (struct nlmsghdr
*)(((char*)nlh
) + aligned_nlmsg_len
);
371 static abi_long
target_to_host_for_each_nlmsg(struct nlmsghdr
*nlh
,
373 abi_long (*target_to_host_nlmsg
)
376 uint32_t aligned_nlmsg_len
;
379 while (len
> sizeof(struct nlmsghdr
)) {
380 if (tswap32(nlh
->nlmsg_len
) < sizeof(struct nlmsghdr
) ||
381 tswap32(nlh
->nlmsg_len
) > len
) {
385 switch (nlh
->nlmsg_type
) {
392 struct nlmsgerr
*e
= NLMSG_DATA(nlh
);
393 e
->error
= tswap32(e
->error
);
394 tswap_nlmsghdr(&e
->msg
);
398 ret
= target_to_host_nlmsg(nlh
);
404 aligned_nlmsg_len
= NLMSG_ALIGN(nlh
->nlmsg_len
);
405 if (aligned_nlmsg_len
>= len
) {
408 len
-= aligned_nlmsg_len
;
409 nlh
= (struct nlmsghdr
*)(((char *)nlh
) + aligned_nlmsg_len
);
414 #ifdef CONFIG_RTNETLINK
415 static abi_long
host_to_target_for_each_nlattr(struct nlattr
*nlattr
,
416 size_t len
, void *context
,
417 abi_long (*host_to_target_nlattr
)
421 unsigned short nla_len
;
422 unsigned short aligned_nla_len
;
425 while (len
> sizeof(struct nlattr
)) {
426 nla_len
= nlattr
->nla_len
;
427 if (nla_len
< sizeof(struct nlattr
) ||
431 ret
= host_to_target_nlattr(nlattr
, context
);
432 nlattr
->nla_len
= tswap16(nlattr
->nla_len
);
433 nlattr
->nla_type
= tswap16(nlattr
->nla_type
);
438 aligned_nla_len
= NLA_ALIGN(nla_len
);
439 if (aligned_nla_len
>= len
) {
442 len
-= aligned_nla_len
;
443 nlattr
= (struct nlattr
*)(((char *)nlattr
) + aligned_nla_len
);
448 static abi_long
host_to_target_for_each_rtattr(struct rtattr
*rtattr
,
450 abi_long (*host_to_target_rtattr
)
453 unsigned short rta_len
;
454 unsigned short aligned_rta_len
;
457 while (len
> sizeof(struct rtattr
)) {
458 rta_len
= rtattr
->rta_len
;
459 if (rta_len
< sizeof(struct rtattr
) ||
463 ret
= host_to_target_rtattr(rtattr
);
464 rtattr
->rta_len
= tswap16(rtattr
->rta_len
);
465 rtattr
->rta_type
= tswap16(rtattr
->rta_type
);
470 aligned_rta_len
= RTA_ALIGN(rta_len
);
471 if (aligned_rta_len
>= len
) {
474 len
-= aligned_rta_len
;
475 rtattr
= (struct rtattr
*)(((char *)rtattr
) + aligned_rta_len
);
480 #define NLA_DATA(nla) ((void *)((char *)(nla)) + NLA_HDRLEN)
482 static abi_long
host_to_target_data_bridge_nlattr(struct nlattr
*nlattr
,
489 switch (nlattr
->nla_type
) {
491 case QEMU_IFLA_BR_FDB_FLUSH
:
494 case QEMU_IFLA_BR_GROUP_ADDR
:
497 case QEMU_IFLA_BR_VLAN_FILTERING
:
498 case QEMU_IFLA_BR_TOPOLOGY_CHANGE
:
499 case QEMU_IFLA_BR_TOPOLOGY_CHANGE_DETECTED
:
500 case QEMU_IFLA_BR_MCAST_ROUTER
:
501 case QEMU_IFLA_BR_MCAST_SNOOPING
:
502 case QEMU_IFLA_BR_MCAST_QUERY_USE_IFADDR
:
503 case QEMU_IFLA_BR_MCAST_QUERIER
:
504 case QEMU_IFLA_BR_NF_CALL_IPTABLES
:
505 case QEMU_IFLA_BR_NF_CALL_IP6TABLES
:
506 case QEMU_IFLA_BR_NF_CALL_ARPTABLES
:
507 case QEMU_IFLA_BR_VLAN_STATS_ENABLED
:
508 case QEMU_IFLA_BR_MCAST_STATS_ENABLED
:
509 case QEMU_IFLA_BR_MCAST_IGMP_VERSION
:
510 case QEMU_IFLA_BR_MCAST_MLD_VERSION
:
511 case QEMU_IFLA_BR_VLAN_STATS_PER_PORT
:
514 case QEMU_IFLA_BR_PRIORITY
:
515 case QEMU_IFLA_BR_VLAN_PROTOCOL
:
516 case QEMU_IFLA_BR_GROUP_FWD_MASK
:
517 case QEMU_IFLA_BR_ROOT_PORT
:
518 case QEMU_IFLA_BR_VLAN_DEFAULT_PVID
:
519 u16
= NLA_DATA(nlattr
);
520 *u16
= tswap16(*u16
);
523 case QEMU_IFLA_BR_FORWARD_DELAY
:
524 case QEMU_IFLA_BR_HELLO_TIME
:
525 case QEMU_IFLA_BR_MAX_AGE
:
526 case QEMU_IFLA_BR_AGEING_TIME
:
527 case QEMU_IFLA_BR_STP_STATE
:
528 case QEMU_IFLA_BR_ROOT_PATH_COST
:
529 case QEMU_IFLA_BR_MCAST_HASH_ELASTICITY
:
530 case QEMU_IFLA_BR_MCAST_HASH_MAX
:
531 case QEMU_IFLA_BR_MCAST_LAST_MEMBER_CNT
:
532 case QEMU_IFLA_BR_MCAST_STARTUP_QUERY_CNT
:
533 u32
= NLA_DATA(nlattr
);
534 *u32
= tswap32(*u32
);
537 case QEMU_IFLA_BR_HELLO_TIMER
:
538 case QEMU_IFLA_BR_TCN_TIMER
:
539 case QEMU_IFLA_BR_GC_TIMER
:
540 case QEMU_IFLA_BR_TOPOLOGY_CHANGE_TIMER
:
541 case QEMU_IFLA_BR_MCAST_LAST_MEMBER_INTVL
:
542 case QEMU_IFLA_BR_MCAST_MEMBERSHIP_INTVL
:
543 case QEMU_IFLA_BR_MCAST_QUERIER_INTVL
:
544 case QEMU_IFLA_BR_MCAST_QUERY_INTVL
:
545 case QEMU_IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
:
546 case QEMU_IFLA_BR_MCAST_STARTUP_QUERY_INTVL
:
547 u64
= NLA_DATA(nlattr
);
548 *u64
= tswap64(*u64
);
550 /* ifla_bridge_id: uin8_t[] */
551 case QEMU_IFLA_BR_ROOT_ID
:
552 case QEMU_IFLA_BR_BRIDGE_ID
:
554 /* br_boolopt_multi { uint32_t, uint32_t } */
555 case QEMU_IFLA_BR_MULTI_BOOLOPT
:
556 u32
= NLA_DATA(nlattr
);
557 u32
[0] = tswap32(u32
[0]); /* optval */
558 u32
[1] = tswap32(u32
[1]); /* optmask */
561 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_BR type %d\n",
568 static abi_long
host_to_target_slave_data_bridge_nlattr(struct nlattr
*nlattr
,
575 switch (nlattr
->nla_type
) {
577 case QEMU_IFLA_BRPORT_STATE
:
578 case QEMU_IFLA_BRPORT_MODE
:
579 case QEMU_IFLA_BRPORT_GUARD
:
580 case QEMU_IFLA_BRPORT_PROTECT
:
581 case QEMU_IFLA_BRPORT_FAST_LEAVE
:
582 case QEMU_IFLA_BRPORT_LEARNING
:
583 case QEMU_IFLA_BRPORT_UNICAST_FLOOD
:
584 case QEMU_IFLA_BRPORT_PROXYARP
:
585 case QEMU_IFLA_BRPORT_LEARNING_SYNC
:
586 case QEMU_IFLA_BRPORT_PROXYARP_WIFI
:
587 case QEMU_IFLA_BRPORT_TOPOLOGY_CHANGE_ACK
:
588 case QEMU_IFLA_BRPORT_CONFIG_PENDING
:
589 case QEMU_IFLA_BRPORT_MULTICAST_ROUTER
:
590 case QEMU_IFLA_BRPORT_MCAST_FLOOD
:
591 case QEMU_IFLA_BRPORT_MCAST_TO_UCAST
:
592 case QEMU_IFLA_BRPORT_VLAN_TUNNEL
:
593 case QEMU_IFLA_BRPORT_BCAST_FLOOD
:
594 case QEMU_IFLA_BRPORT_NEIGH_SUPPRESS
:
595 case QEMU_IFLA_BRPORT_ISOLATED
:
596 case QEMU_IFLA_BRPORT_MRP_RING_OPEN
:
597 case QEMU_IFLA_BRPORT_MRP_IN_OPEN
:
600 case QEMU_IFLA_BRPORT_PRIORITY
:
601 case QEMU_IFLA_BRPORT_DESIGNATED_PORT
:
602 case QEMU_IFLA_BRPORT_DESIGNATED_COST
:
603 case QEMU_IFLA_BRPORT_ID
:
604 case QEMU_IFLA_BRPORT_NO
:
605 case QEMU_IFLA_BRPORT_GROUP_FWD_MASK
:
606 u16
= NLA_DATA(nlattr
);
607 *u16
= tswap16(*u16
);
610 case QEMU_IFLA_BRPORT_COST
:
611 case QEMU_IFLA_BRPORT_BACKUP_PORT
:
612 case QEMU_IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT
:
613 case QEMU_IFLA_BRPORT_MCAST_EHT_HOSTS_CNT
:
614 u32
= NLA_DATA(nlattr
);
615 *u32
= tswap32(*u32
);
618 case QEMU_IFLA_BRPORT_MESSAGE_AGE_TIMER
:
619 case QEMU_IFLA_BRPORT_FORWARD_DELAY_TIMER
:
620 case QEMU_IFLA_BRPORT_HOLD_TIMER
:
621 u64
= NLA_DATA(nlattr
);
622 *u64
= tswap64(*u64
);
624 /* ifla_bridge_id: uint8_t[] */
625 case QEMU_IFLA_BRPORT_ROOT_ID
:
626 case QEMU_IFLA_BRPORT_BRIDGE_ID
:
629 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_BRPORT type %d\n",
636 static abi_long
host_to_target_data_tun_nlattr(struct nlattr
*nlattr
,
641 switch (nlattr
->nla_type
) {
643 case QEMU_IFLA_TUN_TYPE
:
644 case QEMU_IFLA_TUN_PI
:
645 case QEMU_IFLA_TUN_VNET_HDR
:
646 case QEMU_IFLA_TUN_PERSIST
:
647 case QEMU_IFLA_TUN_MULTI_QUEUE
:
650 case QEMU_IFLA_TUN_NUM_QUEUES
:
651 case QEMU_IFLA_TUN_NUM_DISABLED_QUEUES
:
652 case QEMU_IFLA_TUN_OWNER
:
653 case QEMU_IFLA_TUN_GROUP
:
654 u32
= NLA_DATA(nlattr
);
655 *u32
= tswap32(*u32
);
658 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_TUN type %d\n",
665 struct linkinfo_context
{
672 static abi_long
host_to_target_data_linkinfo_nlattr(struct nlattr
*nlattr
,
675 struct linkinfo_context
*li_context
= context
;
677 switch (nlattr
->nla_type
) {
679 case QEMU_IFLA_INFO_KIND
:
680 li_context
->name
= NLA_DATA(nlattr
);
681 li_context
->len
= nlattr
->nla_len
- NLA_HDRLEN
;
683 case QEMU_IFLA_INFO_SLAVE_KIND
:
684 li_context
->slave_name
= NLA_DATA(nlattr
);
685 li_context
->slave_len
= nlattr
->nla_len
- NLA_HDRLEN
;
688 case QEMU_IFLA_INFO_XSTATS
:
689 /* FIXME: only used by CAN */
692 case QEMU_IFLA_INFO_DATA
:
693 if (strncmp(li_context
->name
, "bridge",
694 li_context
->len
) == 0) {
695 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
),
698 host_to_target_data_bridge_nlattr
);
699 } else if (strncmp(li_context
->name
, "tun",
700 li_context
->len
) == 0) {
701 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
),
704 host_to_target_data_tun_nlattr
);
706 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_INFO_KIND %s\n",
710 case QEMU_IFLA_INFO_SLAVE_DATA
:
711 if (strncmp(li_context
->slave_name
, "bridge",
712 li_context
->slave_len
) == 0) {
713 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
),
716 host_to_target_slave_data_bridge_nlattr
);
718 qemu_log_mask(LOG_UNIMP
, "Unknown QEMU_IFLA_INFO_SLAVE_KIND %s\n",
719 li_context
->slave_name
);
723 qemu_log_mask(LOG_UNIMP
, "Unknown host QEMU_IFLA_INFO type: %d\n",
731 static abi_long
host_to_target_data_inet_nlattr(struct nlattr
*nlattr
,
737 switch (nlattr
->nla_type
) {
738 case QEMU_IFLA_INET_CONF
:
739 u32
= NLA_DATA(nlattr
);
740 for (i
= 0; i
< (nlattr
->nla_len
- NLA_HDRLEN
) / sizeof(*u32
);
742 u32
[i
] = tswap32(u32
[i
]);
746 qemu_log_mask(LOG_UNIMP
, "Unknown host AF_INET type: %d\n",
752 static abi_long
host_to_target_data_inet6_nlattr(struct nlattr
*nlattr
,
757 struct ifla_cacheinfo
*ci
;
760 switch (nlattr
->nla_type
) {
762 case QEMU_IFLA_INET6_TOKEN
:
765 case QEMU_IFLA_INET6_ADDR_GEN_MODE
:
768 case QEMU_IFLA_INET6_FLAGS
:
769 u32
= NLA_DATA(nlattr
);
770 *u32
= tswap32(*u32
);
773 case QEMU_IFLA_INET6_CONF
:
774 u32
= NLA_DATA(nlattr
);
775 for (i
= 0; i
< (nlattr
->nla_len
- NLA_HDRLEN
) / sizeof(*u32
);
777 u32
[i
] = tswap32(u32
[i
]);
781 case QEMU_IFLA_INET6_CACHEINFO
:
782 ci
= NLA_DATA(nlattr
);
783 ci
->max_reasm_len
= tswap32(ci
->max_reasm_len
);
784 ci
->tstamp
= tswap32(ci
->tstamp
);
785 ci
->reachable_time
= tswap32(ci
->reachable_time
);
786 ci
->retrans_time
= tswap32(ci
->retrans_time
);
789 case QEMU_IFLA_INET6_STATS
:
790 case QEMU_IFLA_INET6_ICMP6STATS
:
791 u64
= NLA_DATA(nlattr
);
792 for (i
= 0; i
< (nlattr
->nla_len
- NLA_HDRLEN
) / sizeof(*u64
);
794 u64
[i
] = tswap64(u64
[i
]);
798 qemu_log_mask(LOG_UNIMP
, "Unknown host AF_INET6 type: %d\n",
804 static abi_long
host_to_target_data_spec_nlattr(struct nlattr
*nlattr
,
807 switch (nlattr
->nla_type
) {
809 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
), nlattr
->nla_len
,
811 host_to_target_data_inet_nlattr
);
813 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
), nlattr
->nla_len
,
815 host_to_target_data_inet6_nlattr
);
817 qemu_log_mask(LOG_UNIMP
, "Unknown host AF_SPEC type: %d\n",
824 static abi_long
host_to_target_data_xdp_nlattr(struct nlattr
*nlattr
,
829 switch (nlattr
->nla_type
) {
831 case QEMU_IFLA_XDP_ATTACHED
:
834 case QEMU_IFLA_XDP_PROG_ID
:
835 u32
= NLA_DATA(nlattr
);
836 *u32
= tswap32(*u32
);
840 LOG_UNIMP
, "Unknown host XDP type: %d\n", nlattr
->nla_type
);
846 static abi_long
host_to_target_data_vlan_list_nlattr(struct nlattr
*nlattr
,
849 struct ifla_vf_vlan_info
*vlan_info
;
851 switch (nlattr
->nla_type
) {
852 /* struct ifla_vf_vlan_info */
853 case IFLA_VF_VLAN_INFO
:
854 vlan_info
= NLA_DATA(nlattr
);
855 vlan_info
->vf
= tswap32(vlan_info
->vf
);
856 vlan_info
->vlan
= tswap32(vlan_info
->vlan
);
857 vlan_info
->qos
= tswap32(vlan_info
->qos
);
860 qemu_log_mask(LOG_UNIMP
, "Unknown host VLAN LIST type: %d\n",
867 static abi_long
host_to_target_data_vf_stats_nlattr(struct nlattr
*nlattr
,
872 switch (nlattr
->nla_type
) {
874 case QEMU_IFLA_VF_STATS_RX_PACKETS
:
875 case QEMU_IFLA_VF_STATS_TX_PACKETS
:
876 case QEMU_IFLA_VF_STATS_RX_BYTES
:
877 case QEMU_IFLA_VF_STATS_TX_BYTES
:
878 case QEMU_IFLA_VF_STATS_BROADCAST
:
879 case QEMU_IFLA_VF_STATS_MULTICAST
:
880 case QEMU_IFLA_VF_STATS_PAD
:
881 case QEMU_IFLA_VF_STATS_RX_DROPPED
:
882 case QEMU_IFLA_VF_STATS_TX_DROPPED
:
883 u64
= NLA_DATA(nlattr
);
884 *u64
= tswap64(*u64
);
887 qemu_log_mask(LOG_UNIMP
, "Unknown host VF STATS type: %d\n",
894 static abi_long
host_to_target_data_vfinfo_nlattr(struct nlattr
*nlattr
,
897 struct ifla_vf_mac
*mac
;
898 struct ifla_vf_vlan
*vlan
;
899 struct ifla_vf_vlan_info
*vlan_info
;
900 struct ifla_vf_spoofchk
*spoofchk
;
901 struct ifla_vf_rate
*rate
;
902 struct ifla_vf_link_state
*link_state
;
903 struct ifla_vf_rss_query_en
*rss_query_en
;
904 struct ifla_vf_trust
*trust
;
905 struct ifla_vf_guid
*guid
;
907 switch (nlattr
->nla_type
) {
908 /* struct ifla_vf_mac */
909 case QEMU_IFLA_VF_MAC
:
910 mac
= NLA_DATA(nlattr
);
911 mac
->vf
= tswap32(mac
->vf
);
913 /* struct ifla_vf_broadcast */
914 case QEMU_IFLA_VF_BROADCAST
:
916 /* struct struct ifla_vf_vlan */
917 case QEMU_IFLA_VF_VLAN
:
918 vlan
= NLA_DATA(nlattr
);
919 vlan
->vf
= tswap32(vlan
->vf
);
920 vlan
->vlan
= tswap32(vlan
->vlan
);
921 vlan
->qos
= tswap32(vlan
->qos
);
923 /* struct ifla_vf_vlan_info */
924 case QEMU_IFLA_VF_TX_RATE
:
925 vlan_info
= NLA_DATA(nlattr
);
926 vlan_info
->vf
= tswap32(vlan_info
->vf
);
927 vlan_info
->vlan
= tswap32(vlan_info
->vlan
);
928 vlan_info
->qos
= tswap32(vlan_info
->qos
);
930 /* struct ifla_vf_spoofchk */
931 case QEMU_IFLA_VF_SPOOFCHK
:
932 spoofchk
= NLA_DATA(nlattr
);
933 spoofchk
->vf
= tswap32(spoofchk
->vf
);
934 spoofchk
->setting
= tswap32(spoofchk
->setting
);
936 /* struct ifla_vf_rate */
937 case QEMU_IFLA_VF_RATE
:
938 rate
= NLA_DATA(nlattr
);
939 rate
->vf
= tswap32(rate
->vf
);
940 rate
->min_tx_rate
= tswap32(rate
->min_tx_rate
);
941 rate
->max_tx_rate
= tswap32(rate
->max_tx_rate
);
943 /* struct ifla_vf_link_state */
944 case QEMU_IFLA_VF_LINK_STATE
:
945 link_state
= NLA_DATA(nlattr
);
946 link_state
->vf
= tswap32(link_state
->vf
);
947 link_state
->link_state
= tswap32(link_state
->link_state
);
949 /* struct ifla_vf_rss_query_en */
950 case QEMU_IFLA_VF_RSS_QUERY_EN
:
951 rss_query_en
= NLA_DATA(nlattr
);
952 rss_query_en
->vf
= tswap32(rss_query_en
->vf
);
953 rss_query_en
->setting
= tswap32(rss_query_en
->setting
);
955 /* struct ifla_vf_trust */
956 case QEMU_IFLA_VF_TRUST
:
957 trust
= NLA_DATA(nlattr
);
958 trust
->vf
= tswap32(trust
->vf
);
959 trust
->setting
= tswap32(trust
->setting
);
961 /* struct ifla_vf_guid */
962 case QEMU_IFLA_VF_IB_NODE_GUID
:
963 case QEMU_IFLA_VF_IB_PORT_GUID
:
964 guid
= NLA_DATA(nlattr
);
965 guid
->vf
= tswap32(guid
->vf
);
966 guid
->guid
= tswap32(guid
->guid
);
969 case QEMU_IFLA_VF_VLAN_LIST
:
970 return host_to_target_for_each_nlattr(RTA_DATA(nlattr
), nlattr
->nla_len
,
972 host_to_target_data_vlan_list_nlattr
);
973 case QEMU_IFLA_VF_STATS
:
974 return host_to_target_for_each_nlattr(RTA_DATA(nlattr
), nlattr
->nla_len
,
976 host_to_target_data_vf_stats_nlattr
);
978 qemu_log_mask(LOG_UNIMP
, "Unknown host VFINFO type: %d\n",
985 static abi_long
host_to_target_data_link_rtattr(struct rtattr
*rtattr
)
988 struct rtnl_link_stats
*st
;
989 struct rtnl_link_stats64
*st64
;
990 struct rtnl_link_ifmap
*map
;
991 struct linkinfo_context li_context
;
993 switch (rtattr
->rta_type
) {
995 case QEMU_IFLA_ADDRESS
:
996 case QEMU_IFLA_BROADCAST
:
997 case QEMU_IFLA_PERM_ADDRESS
:
998 case QEMU_IFLA_PHYS_PORT_ID
:
1000 case QEMU_IFLA_IFNAME
:
1001 case QEMU_IFLA_QDISC
:
1002 case QEMU_IFLA_PARENT_DEV_NAME
:
1003 case QEMU_IFLA_PARENT_DEV_BUS_NAME
:
1006 case QEMU_IFLA_OPERSTATE
:
1007 case QEMU_IFLA_LINKMODE
:
1008 case QEMU_IFLA_CARRIER
:
1009 case QEMU_IFLA_PROTO_DOWN
:
1013 case QEMU_IFLA_LINK
:
1014 case QEMU_IFLA_WEIGHT
:
1015 case QEMU_IFLA_TXQLEN
:
1016 case QEMU_IFLA_CARRIER_CHANGES
:
1017 case QEMU_IFLA_NUM_RX_QUEUES
:
1018 case QEMU_IFLA_NUM_TX_QUEUES
:
1019 case QEMU_IFLA_PROMISCUITY
:
1020 case QEMU_IFLA_EXT_MASK
:
1021 case QEMU_IFLA_LINK_NETNSID
:
1022 case QEMU_IFLA_GROUP
:
1023 case QEMU_IFLA_MASTER
:
1024 case QEMU_IFLA_NUM_VF
:
1025 case QEMU_IFLA_GSO_MAX_SEGS
:
1026 case QEMU_IFLA_GSO_MAX_SIZE
:
1027 case QEMU_IFLA_CARRIER_UP_COUNT
:
1028 case QEMU_IFLA_CARRIER_DOWN_COUNT
:
1029 case QEMU_IFLA_MIN_MTU
:
1030 case QEMU_IFLA_MAX_MTU
:
1031 u32
= RTA_DATA(rtattr
);
1032 *u32
= tswap32(*u32
);
1034 /* struct rtnl_link_stats */
1035 case QEMU_IFLA_STATS
:
1036 st
= RTA_DATA(rtattr
);
1037 st
->rx_packets
= tswap32(st
->rx_packets
);
1038 st
->tx_packets
= tswap32(st
->tx_packets
);
1039 st
->rx_bytes
= tswap32(st
->rx_bytes
);
1040 st
->tx_bytes
= tswap32(st
->tx_bytes
);
1041 st
->rx_errors
= tswap32(st
->rx_errors
);
1042 st
->tx_errors
= tswap32(st
->tx_errors
);
1043 st
->rx_dropped
= tswap32(st
->rx_dropped
);
1044 st
->tx_dropped
= tswap32(st
->tx_dropped
);
1045 st
->multicast
= tswap32(st
->multicast
);
1046 st
->collisions
= tswap32(st
->collisions
);
1048 /* detailed rx_errors: */
1049 st
->rx_length_errors
= tswap32(st
->rx_length_errors
);
1050 st
->rx_over_errors
= tswap32(st
->rx_over_errors
);
1051 st
->rx_crc_errors
= tswap32(st
->rx_crc_errors
);
1052 st
->rx_frame_errors
= tswap32(st
->rx_frame_errors
);
1053 st
->rx_fifo_errors
= tswap32(st
->rx_fifo_errors
);
1054 st
->rx_missed_errors
= tswap32(st
->rx_missed_errors
);
1056 /* detailed tx_errors */
1057 st
->tx_aborted_errors
= tswap32(st
->tx_aborted_errors
);
1058 st
->tx_carrier_errors
= tswap32(st
->tx_carrier_errors
);
1059 st
->tx_fifo_errors
= tswap32(st
->tx_fifo_errors
);
1060 st
->tx_heartbeat_errors
= tswap32(st
->tx_heartbeat_errors
);
1061 st
->tx_window_errors
= tswap32(st
->tx_window_errors
);
1064 st
->rx_compressed
= tswap32(st
->rx_compressed
);
1065 st
->tx_compressed
= tswap32(st
->tx_compressed
);
1067 /* struct rtnl_link_stats64 */
1068 case QEMU_IFLA_STATS64
:
1069 st64
= RTA_DATA(rtattr
);
1070 st64
->rx_packets
= tswap64(st64
->rx_packets
);
1071 st64
->tx_packets
= tswap64(st64
->tx_packets
);
1072 st64
->rx_bytes
= tswap64(st64
->rx_bytes
);
1073 st64
->tx_bytes
= tswap64(st64
->tx_bytes
);
1074 st64
->rx_errors
= tswap64(st64
->rx_errors
);
1075 st64
->tx_errors
= tswap64(st64
->tx_errors
);
1076 st64
->rx_dropped
= tswap64(st64
->rx_dropped
);
1077 st64
->tx_dropped
= tswap64(st64
->tx_dropped
);
1078 st64
->multicast
= tswap64(st64
->multicast
);
1079 st64
->collisions
= tswap64(st64
->collisions
);
1081 /* detailed rx_errors: */
1082 st64
->rx_length_errors
= tswap64(st64
->rx_length_errors
);
1083 st64
->rx_over_errors
= tswap64(st64
->rx_over_errors
);
1084 st64
->rx_crc_errors
= tswap64(st64
->rx_crc_errors
);
1085 st64
->rx_frame_errors
= tswap64(st64
->rx_frame_errors
);
1086 st64
->rx_fifo_errors
= tswap64(st64
->rx_fifo_errors
);
1087 st64
->rx_missed_errors
= tswap64(st64
->rx_missed_errors
);
1089 /* detailed tx_errors */
1090 st64
->tx_aborted_errors
= tswap64(st64
->tx_aborted_errors
);
1091 st64
->tx_carrier_errors
= tswap64(st64
->tx_carrier_errors
);
1092 st64
->tx_fifo_errors
= tswap64(st64
->tx_fifo_errors
);
1093 st64
->tx_heartbeat_errors
= tswap64(st64
->tx_heartbeat_errors
);
1094 st64
->tx_window_errors
= tswap64(st64
->tx_window_errors
);
1097 st64
->rx_compressed
= tswap64(st64
->rx_compressed
);
1098 st64
->tx_compressed
= tswap64(st64
->tx_compressed
);
1100 /* struct rtnl_link_ifmap */
1102 map
= RTA_DATA(rtattr
);
1103 map
->mem_start
= tswap64(map
->mem_start
);
1104 map
->mem_end
= tswap64(map
->mem_end
);
1105 map
->base_addr
= tswap64(map
->base_addr
);
1106 map
->irq
= tswap16(map
->irq
);
1109 case QEMU_IFLA_LINKINFO
:
1110 memset(&li_context
, 0, sizeof(li_context
));
1111 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
1113 host_to_target_data_linkinfo_nlattr
);
1114 case QEMU_IFLA_AF_SPEC
:
1115 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
1117 host_to_target_data_spec_nlattr
);
1119 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
1121 host_to_target_data_xdp_nlattr
);
1122 case QEMU_IFLA_VFINFO_LIST
:
1123 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
1125 host_to_target_data_vfinfo_nlattr
);
1127 qemu_log_mask(LOG_UNIMP
, "Unknown host QEMU_IFLA type: %d\n",
1134 static abi_long
host_to_target_data_addr_rtattr(struct rtattr
*rtattr
)
1137 struct ifa_cacheinfo
*ci
;
1139 switch (rtattr
->rta_type
) {
1140 /* binary: depends on family type */
1150 u32
= RTA_DATA(rtattr
);
1151 *u32
= tswap32(*u32
);
1153 /* struct ifa_cacheinfo */
1155 ci
= RTA_DATA(rtattr
);
1156 ci
->ifa_prefered
= tswap32(ci
->ifa_prefered
);
1157 ci
->ifa_valid
= tswap32(ci
->ifa_valid
);
1158 ci
->cstamp
= tswap32(ci
->cstamp
);
1159 ci
->tstamp
= tswap32(ci
->tstamp
);
1163 LOG_UNIMP
, "Unknown host IFA type: %d\n", rtattr
->rta_type
);
1169 static abi_long
host_to_target_data_route_rtattr(struct rtattr
*rtattr
)
1172 struct rta_cacheinfo
*ci
;
1174 switch (rtattr
->rta_type
) {
1175 /* binary: depends on family type */
1176 case QEMU_RTA_GATEWAY
:
1178 case QEMU_RTA_PREFSRC
:
1184 case QEMU_RTA_PRIORITY
:
1185 case QEMU_RTA_TABLE
:
1187 u32
= RTA_DATA(rtattr
);
1188 *u32
= tswap32(*u32
);
1190 /* struct rta_cacheinfo */
1191 case QEMU_RTA_CACHEINFO
:
1192 ci
= RTA_DATA(rtattr
);
1193 ci
->rta_clntref
= tswap32(ci
->rta_clntref
);
1194 ci
->rta_lastuse
= tswap32(ci
->rta_lastuse
);
1195 ci
->rta_expires
= tswap32(ci
->rta_expires
);
1196 ci
->rta_error
= tswap32(ci
->rta_error
);
1197 ci
->rta_used
= tswap32(ci
->rta_used
);
1198 #if defined(RTNETLINK_HAVE_PEERINFO)
1199 ci
->rta_id
= tswap32(ci
->rta_id
);
1200 ci
->rta_ts
= tswap32(ci
->rta_ts
);
1201 ci
->rta_tsage
= tswap32(ci
->rta_tsage
);
1206 LOG_UNIMP
, "Unknown host RTA type: %d\n", rtattr
->rta_type
);
1212 static abi_long
host_to_target_link_rtattr(struct rtattr
*rtattr
,
1213 uint32_t rtattr_len
)
1215 return host_to_target_for_each_rtattr(rtattr
, rtattr_len
,
1216 host_to_target_data_link_rtattr
);
1219 static abi_long
host_to_target_addr_rtattr(struct rtattr
*rtattr
,
1220 uint32_t rtattr_len
)
1222 return host_to_target_for_each_rtattr(rtattr
, rtattr_len
,
1223 host_to_target_data_addr_rtattr
);
1226 static abi_long
host_to_target_route_rtattr(struct rtattr
*rtattr
,
1227 uint32_t rtattr_len
)
1229 return host_to_target_for_each_rtattr(rtattr
, rtattr_len
,
1230 host_to_target_data_route_rtattr
);
1233 static abi_long
host_to_target_data_route(struct nlmsghdr
*nlh
)
1236 struct ifinfomsg
*ifi
;
1237 struct ifaddrmsg
*ifa
;
1240 nlmsg_len
= nlh
->nlmsg_len
;
1241 switch (nlh
->nlmsg_type
) {
1245 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifi
))) {
1246 ifi
= NLMSG_DATA(nlh
);
1247 ifi
->ifi_type
= tswap16(ifi
->ifi_type
);
1248 ifi
->ifi_index
= tswap32(ifi
->ifi_index
);
1249 ifi
->ifi_flags
= tswap32(ifi
->ifi_flags
);
1250 ifi
->ifi_change
= tswap32(ifi
->ifi_change
);
1251 host_to_target_link_rtattr(IFLA_RTA(ifi
),
1252 nlmsg_len
- NLMSG_LENGTH(sizeof(*ifi
)));
1258 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifa
))) {
1259 ifa
= NLMSG_DATA(nlh
);
1260 ifa
->ifa_index
= tswap32(ifa
->ifa_index
);
1261 host_to_target_addr_rtattr(IFA_RTA(ifa
),
1262 nlmsg_len
- NLMSG_LENGTH(sizeof(*ifa
)));
1268 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*rtm
))) {
1269 rtm
= NLMSG_DATA(nlh
);
1270 rtm
->rtm_flags
= tswap32(rtm
->rtm_flags
);
1271 host_to_target_route_rtattr(RTM_RTA(rtm
),
1272 nlmsg_len
- NLMSG_LENGTH(sizeof(*rtm
)));
1276 return -TARGET_EINVAL
;
1281 static inline abi_long
host_to_target_nlmsg_route(struct nlmsghdr
*nlh
,
1284 return host_to_target_for_each_nlmsg(nlh
, len
, host_to_target_data_route
);
1287 static abi_long
target_to_host_for_each_rtattr(struct rtattr
*rtattr
,
1289 abi_long (*target_to_host_rtattr
)
1292 unsigned short aligned_rta_len
;
1295 while (len
>= sizeof(struct rtattr
)) {
1296 if (tswap16(rtattr
->rta_len
) < sizeof(struct rtattr
) ||
1297 tswap16(rtattr
->rta_len
) > len
) {
1300 rtattr
->rta_len
= tswap16(rtattr
->rta_len
);
1301 rtattr
->rta_type
= tswap16(rtattr
->rta_type
);
1302 ret
= target_to_host_rtattr(rtattr
);
1307 aligned_rta_len
= RTA_ALIGN(rtattr
->rta_len
);
1308 if (aligned_rta_len
>= len
) {
1311 len
-= aligned_rta_len
;
1312 rtattr
= (struct rtattr
*)(((char *)rtattr
) + aligned_rta_len
);
1317 static abi_long
target_to_host_data_link_rtattr(struct rtattr
*rtattr
)
1321 switch (rtattr
->rta_type
) {
1323 case QEMU_IFLA_EXT_MASK
:
1324 u32
= RTA_DATA(rtattr
);
1325 *u32
= tswap32(*u32
);
1328 qemu_log_mask(LOG_UNIMP
, "Unknown target QEMU_IFLA type: %d\n",
1335 static abi_long
target_to_host_data_addr_rtattr(struct rtattr
*rtattr
)
1337 switch (rtattr
->rta_type
) {
1338 /* binary: depends on family type */
1343 qemu_log_mask(LOG_UNIMP
, "Unknown target IFA type: %d\n",
1350 static abi_long
target_to_host_data_route_rtattr(struct rtattr
*rtattr
)
1353 switch (rtattr
->rta_type
) {
1354 /* binary: depends on family type */
1357 case QEMU_RTA_GATEWAY
:
1360 case QEMU_RTA_PRIORITY
:
1361 case QEMU_RTA_TABLE
:
1363 u32
= RTA_DATA(rtattr
);
1364 *u32
= tswap32(*u32
);
1367 qemu_log_mask(LOG_UNIMP
, "Unknown target RTA type: %d\n",
1374 static void target_to_host_link_rtattr(struct rtattr
*rtattr
,
1375 uint32_t rtattr_len
)
1377 target_to_host_for_each_rtattr(rtattr
, rtattr_len
,
1378 target_to_host_data_link_rtattr
);
1381 static void target_to_host_addr_rtattr(struct rtattr
*rtattr
,
1382 uint32_t rtattr_len
)
1384 target_to_host_for_each_rtattr(rtattr
, rtattr_len
,
1385 target_to_host_data_addr_rtattr
);
1388 static void target_to_host_route_rtattr(struct rtattr
*rtattr
,
1389 uint32_t rtattr_len
)
1391 target_to_host_for_each_rtattr(rtattr
, rtattr_len
,
1392 target_to_host_data_route_rtattr
);
1395 static abi_long
target_to_host_data_route(struct nlmsghdr
*nlh
)
1397 struct ifinfomsg
*ifi
;
1398 struct ifaddrmsg
*ifa
;
1401 switch (nlh
->nlmsg_type
) {
1406 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifi
))) {
1407 ifi
= NLMSG_DATA(nlh
);
1408 ifi
->ifi_type
= tswap16(ifi
->ifi_type
);
1409 ifi
->ifi_index
= tswap32(ifi
->ifi_index
);
1410 ifi
->ifi_flags
= tswap32(ifi
->ifi_flags
);
1411 ifi
->ifi_change
= tswap32(ifi
->ifi_change
);
1412 target_to_host_link_rtattr(IFLA_RTA(ifi
), nlh
->nlmsg_len
-
1413 NLMSG_LENGTH(sizeof(*ifi
)));
1419 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifa
))) {
1420 ifa
= NLMSG_DATA(nlh
);
1421 ifa
->ifa_index
= tswap32(ifa
->ifa_index
);
1422 target_to_host_addr_rtattr(IFA_RTA(ifa
), nlh
->nlmsg_len
-
1423 NLMSG_LENGTH(sizeof(*ifa
)));
1429 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*rtm
))) {
1430 rtm
= NLMSG_DATA(nlh
);
1431 rtm
->rtm_flags
= tswap32(rtm
->rtm_flags
);
1432 target_to_host_route_rtattr(RTM_RTA(rtm
), nlh
->nlmsg_len
-
1433 NLMSG_LENGTH(sizeof(*rtm
)));
1437 return -TARGET_EOPNOTSUPP
;
1442 static abi_long
target_to_host_nlmsg_route(struct nlmsghdr
*nlh
, size_t len
)
1444 return target_to_host_for_each_nlmsg(nlh
, len
, target_to_host_data_route
);
1446 #endif /* CONFIG_RTNETLINK */
1448 static abi_long
host_to_target_data_audit(struct nlmsghdr
*nlh
)
1450 switch (nlh
->nlmsg_type
) {
1452 qemu_log_mask(LOG_UNIMP
, "Unknown host audit message type %d\n",
1454 return -TARGET_EINVAL
;
1459 static inline abi_long
host_to_target_nlmsg_audit(struct nlmsghdr
*nlh
,
1462 return host_to_target_for_each_nlmsg(nlh
, len
, host_to_target_data_audit
);
1465 static abi_long
target_to_host_data_audit(struct nlmsghdr
*nlh
)
1467 switch (nlh
->nlmsg_type
) {
1469 case AUDIT_FIRST_USER_MSG
... AUDIT_LAST_USER_MSG
:
1470 case AUDIT_FIRST_USER_MSG2
... AUDIT_LAST_USER_MSG2
:
1473 qemu_log_mask(LOG_UNIMP
, "Unknown target audit message type %d\n",
1475 return -TARGET_EINVAL
;
1481 static abi_long
target_to_host_nlmsg_audit(struct nlmsghdr
*nlh
, size_t len
)
1483 return target_to_host_for_each_nlmsg(nlh
, len
, target_to_host_data_audit
);
1486 static abi_long
packet_target_to_host_sockaddr(void *host_addr
,
1487 abi_ulong target_addr
,
1490 struct sockaddr
*addr
= host_addr
;
1491 struct target_sockaddr
*target_saddr
;
1493 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1494 if (!target_saddr
) {
1495 return -TARGET_EFAULT
;
1498 memcpy(addr
, target_saddr
, len
);
1499 addr
->sa_family
= tswap16(target_saddr
->sa_family
);
1500 /* spkt_protocol is big-endian */
1502 unlock_user(target_saddr
, target_addr
, 0);
1506 TargetFdTrans target_packet_trans
= {
1507 .target_to_host_addr
= packet_target_to_host_sockaddr
,
1510 #ifdef CONFIG_RTNETLINK
1511 static abi_long
netlink_route_target_to_host(void *buf
, size_t len
)
1515 ret
= target_to_host_nlmsg_route(buf
, len
);
1523 static abi_long
netlink_route_host_to_target(void *buf
, size_t len
)
1527 ret
= host_to_target_nlmsg_route(buf
, len
);
1535 TargetFdTrans target_netlink_route_trans
= {
1536 .target_to_host_data
= netlink_route_target_to_host
,
1537 .host_to_target_data
= netlink_route_host_to_target
,
1539 #endif /* CONFIG_RTNETLINK */
1541 static abi_long
netlink_audit_target_to_host(void *buf
, size_t len
)
1545 ret
= target_to_host_nlmsg_audit(buf
, len
);
1553 static abi_long
netlink_audit_host_to_target(void *buf
, size_t len
)
1557 ret
= host_to_target_nlmsg_audit(buf
, len
);
1565 TargetFdTrans target_netlink_audit_trans
= {
1566 .target_to_host_data
= netlink_audit_target_to_host
,
1567 .host_to_target_data
= netlink_audit_host_to_target
,
1570 /* signalfd siginfo conversion */
1573 host_to_target_signalfd_siginfo(struct signalfd_siginfo
*tinfo
,
1574 const struct signalfd_siginfo
*info
)
1576 int sig
= host_to_target_signal(info
->ssi_signo
);
1578 /* linux/signalfd.h defines a ssi_addr_lsb
1579 * not defined in sys/signalfd.h but used by some kernels
1582 #ifdef BUS_MCEERR_AO
1583 if (tinfo
->ssi_signo
== SIGBUS
&&
1584 (tinfo
->ssi_code
== BUS_MCEERR_AR
||
1585 tinfo
->ssi_code
== BUS_MCEERR_AO
)) {
1586 uint16_t *ssi_addr_lsb
= (uint16_t *)(&info
->ssi_addr
+ 1);
1587 uint16_t *tssi_addr_lsb
= (uint16_t *)(&tinfo
->ssi_addr
+ 1);
1588 *tssi_addr_lsb
= tswap16(*ssi_addr_lsb
);
1592 tinfo
->ssi_signo
= tswap32(sig
);
1593 tinfo
->ssi_errno
= tswap32(tinfo
->ssi_errno
);
1594 tinfo
->ssi_code
= tswap32(info
->ssi_code
);
1595 tinfo
->ssi_pid
= tswap32(info
->ssi_pid
);
1596 tinfo
->ssi_uid
= tswap32(info
->ssi_uid
);
1597 tinfo
->ssi_fd
= tswap32(info
->ssi_fd
);
1598 tinfo
->ssi_tid
= tswap32(info
->ssi_tid
);
1599 tinfo
->ssi_band
= tswap32(info
->ssi_band
);
1600 tinfo
->ssi_overrun
= tswap32(info
->ssi_overrun
);
1601 tinfo
->ssi_trapno
= tswap32(info
->ssi_trapno
);
1602 tinfo
->ssi_status
= tswap32(info
->ssi_status
);
1603 tinfo
->ssi_int
= tswap32(info
->ssi_int
);
1604 tinfo
->ssi_ptr
= tswap64(info
->ssi_ptr
);
1605 tinfo
->ssi_utime
= tswap64(info
->ssi_utime
);
1606 tinfo
->ssi_stime
= tswap64(info
->ssi_stime
);
1607 tinfo
->ssi_addr
= tswap64(info
->ssi_addr
);
1610 static abi_long
host_to_target_data_signalfd(void *buf
, size_t len
)
1614 for (i
= 0; i
< len
; i
+= sizeof(struct signalfd_siginfo
)) {
1615 host_to_target_signalfd_siginfo(buf
+ i
, buf
+ i
);
1621 TargetFdTrans target_signalfd_trans
= {
1622 .host_to_target_data
= host_to_target_data_signalfd
,
1625 static abi_long
swap_data_eventfd(void *buf
, size_t len
)
1627 uint64_t *counter
= buf
;
1630 if (len
< sizeof(uint64_t)) {
1634 for (i
= 0; i
< len
; i
+= sizeof(uint64_t)) {
1635 *counter
= tswap64(*counter
);
1642 TargetFdTrans target_eventfd_trans
= {
1643 .host_to_target_data
= swap_data_eventfd
,
1644 .target_to_host_data
= swap_data_eventfd
,
1647 #if defined(CONFIG_INOTIFY) && (defined(TARGET_NR_inotify_init) || \
1648 defined(TARGET_NR_inotify_init1))
1649 static abi_long
host_to_target_data_inotify(void *buf
, size_t len
)
1651 struct inotify_event
*ev
;
1655 for (i
= 0; i
< len
; i
+= sizeof(struct inotify_event
) + name_len
) {
1656 ev
= (struct inotify_event
*)((char *)buf
+ i
);
1659 ev
->wd
= tswap32(ev
->wd
);
1660 ev
->mask
= tswap32(ev
->mask
);
1661 ev
->cookie
= tswap32(ev
->cookie
);
1662 ev
->len
= tswap32(name_len
);
1668 TargetFdTrans target_inotify_trans
= {
1669 .host_to_target_data
= host_to_target_data_inotify
,