On 4/29/2026 7:45 AM, Warner Losh wrote:
> Add special handler for IPv6 interface request ioctls that take
> a sockaddr_in6 structure as input and return an integer flag value,
> such as SIOCGIFAFLAG_IN6 and SIOCGIFALIFETIME_IN6.
> 
> Signed-off-by: Stacey D. Son <[email protected]>
> Signed-off-by: Warner Losh <[email protected]>
> ---
>  bsd-user/bsd-ioctl.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/bsd-user/bsd-ioctl.c b/bsd-user/bsd-ioctl.c
> index 2ff37a0817..aa0153bbaa 100644
> --- a/bsd-user/bsd-ioctl.c
> +++ b/bsd-user/bsd-ioctl.c
> @@ -262,3 +262,35 @@ static void target_to_host_sockaddr_in6(struct 
> sockaddr_in6 *hsa_in6,
>      memcpy(&hsa_in6->sin6_addr, &tsa_in6->sin6_addr, 16);
>      __get_user(hsa_in6->sin6_scope_id, &tsa_in6->sin6_scope_id);
>  }
> +
> +/*
> + * For ioctl()'s such as SIOCGIFAFLAG_IN6 and SIOCGIFALIFETIME_IN6 that
> + * passes a struct sockaddr_in6 in and gets an int out using
> + * struct in6_ifreq.
> + */
> +static abi_long do_ioctl_in6_ifreq_sockaddr_int(const IOCTLEntry *ie,
> +        uint8_t *buf_temp, int fd, abi_long cmd, abi_long arg)
> +{
> +    abi_long ret;
> +    struct target_in6_ifreq *tin6ifreq;
> +    struct target_sockaddr_in6 *tsa_in6;
> +    struct in6_ifreq hin6ifreq;
> +    struct sockaddr_in6 *hsa_in6 = &hin6ifreq.ifr_ifru.ifru_addr;
> +
> +    tin6ifreq = lock_user(VERIFY_WRITE, arg, sizeof(*tin6ifreq), 0);
> +    if (tin6ifreq == NULL) {
> +        return -TARGET_EFAULT;
> +    }
> +    memcpy(hin6ifreq.ifr_name, tin6ifreq->ifr_name, IFNAMSIZ);
> +    tsa_in6 = &tin6ifreq->ifr_ifru.ifru_addr;
> +    target_to_host_sockaddr_in6(hsa_in6, tsa_in6);
> +
> +    ret = get_errno(safe_ioctl(fd, ie->host_cmd, &hin6ifreq));
> +    if (!is_error(ret)) {
> +        put_user_s32(hin6ifreq.ifr_ifru.ifru_flags6,
> +                arg + offsetof(struct target_in6_ifreq, 
> ifr_ifru.ifru_flags6));
> +    }
> +    unlock_user(tin6ifreq, arg, 1);
> +
> +    return ret;
> +}
> 

Reviewed-by: Pierrick Bouvier <[email protected]>


Reply via email to