NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA



The following reply was made to PR kern/58235; it has been noted by GNATS.

From: Martin Husemann <martin%duskware.de@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Wed, 8 May 2024 20:05:55 +0200

 Here is a patch that works, but it seems the compiler needs the 
 __packed and the manual alignement, else the struct has the same size
 as the native version (at least on amd64).
 
 Ugly - any better tricks?
 
 Martin
 
 Index: netbsd32_ioctl.c
 ===================================================================
 RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_ioctl.c,v
 retrieving revision 1.120
 diff -u -p -r1.120 netbsd32_ioctl.c
 --- netbsd32_ioctl.c	22 Dec 2021 00:21:32 -0000	1.120
 +++ netbsd32_ioctl.c	8 May 2024 18:03:41 -0000
 @@ -151,6 +151,20 @@ netbsd32_to_oifreq(struct netbsd32_oifre
  }
  
  static inline void
 +netbsd32_to_ifdatareq(struct netbsd32_ifdatareq *s32p, struct ifdatareq *p, u_long cmd)
 +{
 +
 +	memcpy(p, s32p, sizeof *s32p);
 +	switch (cmd) {
 +	case SIOCGIFDATA:
 +	case SIOCZIFDATA:
 +		netbsd32_to_timespec(&s32p->ifdr_data.ifi_lastchange,
 +		    &p->ifdr_data.ifi_lastchange);
 +		break;
 +	}
 +}
 +
 +static inline void
  netbsd32_to_if_addrprefreq(const struct netbsd32_if_addrprefreq *ifap32,
      struct if_addrprefreq *ifap, u_long cmd)
  {
 @@ -693,6 +707,20 @@ netbsd32_from_oifreq(struct oifreq *p,
  }
  
  static inline void
 +netbsd32_from_ifdatareq(const struct ifdatareq *p, struct netbsd32_ifdatareq *p32, u_long cmd)
 +{
 +
 +	memcpy(p32, p, sizeof *p32);
 +	switch (cmd) {
 +	case SIOCGIFDATA:
 +	case SIOCZIFDATA:
 +		netbsd32_from_timespec(&p->ifdr_data.ifi_lastchange,
 +		    &p32->ifdr_data.ifi_lastchange);
 +		break;
 +	}
 +}
 +
 +static inline void
  netbsd32_from_if_addrprefreq(const struct if_addrprefreq *ifap,
      struct netbsd32_if_addrprefreq *ifap32, u_long cmd)
  {
 @@ -1537,6 +1565,10 @@ netbsd32_ioctl(struct lwp *l,
  	case SIOCSIFADDRPREF32:
  		IOCTL_STRUCT_CONV_TO(SIOCSIFADDRPREF, if_addrprefreq);
  
 +	case SIOCGIFDATA32:
 +		IOCTL_STRUCT_CONV_TO(SIOCGIFDATA, ifdatareq);
 +	case SIOCZIFDATA32:
 +		IOCTL_STRUCT_CONV_TO(SIOCZIFDATA, ifdatareq);
  
  	case OSIOCGIFFLAGS32:
  		IOCTL_STRUCT_CONV_TO(OSIOCGIFFLAGS, oifreq);
 Index: netbsd32_ioctl.h
 ===================================================================
 RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_ioctl.h,v
 retrieving revision 1.79
 diff -u -p -r1.79 netbsd32_ioctl.h
 --- netbsd32_ioctl.h	22 Dec 2021 00:21:32 -0000	1.79
 +++ netbsd32_ioctl.h	8 May 2024 18:03:41 -0000
 @@ -316,6 +316,35 @@ struct netbsd32_if_clonereq {
  	netbsd32_charp ifcr_buffer;
  };
  
 +struct netbsd32_if_data {
 +	u_char	ifi_type;
 +	u_char	ifi_addrlen;
 +	u_char	ifi_hdrlen;
 +	u_char  __pack_dummy;
 +	int	ifi_link_state;
 +	uint64_t ifi_mtu;
 +	uint64_t ifi_metric;
 +	uint64_t ifi_baudrate;
 +	uint64_t ifi_ipackets;
 +	uint64_t ifi_ierrors;
 +	uint64_t ifi_opackets;
 +	uint64_t ifi_oerrors;
 +	uint64_t ifi_collisions;
 +	uint64_t ifi_ibytes;
 +	uint64_t ifi_obytes;
 +	uint64_t ifi_imcasts;
 +	uint64_t ifi_omcasts;
 +	uint64_t ifi_iqdrops;
 +	uint64_t ifi_noproto;
 +	struct	netbsd32_timespec ifi_lastchange;
 +} __packed;
 +
 +struct netbsd32_ifdatareq {
 +	char	ifdr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
 +	struct	netbsd32_if_data ifdr_data;
 +};
 +
 +
  /* from <dev/pci/if_devar.h> */
  #define	SIOCGADDRROM32		_IOW('i', 240, struct netbsd32_ifreq)	/* get 128 bytes of ROM */
  #define	SIOCGCHIPID32		_IOWR('i', 241, struct netbsd32_ifreq)	/* get chipid */
 @@ -388,6 +417,10 @@ struct netbsd32_if_clonereq {
  
  #define	SIOCGIFMTU32	_IOWR('i', 126, struct netbsd32_ifreq)	/* get ifnet mtu */
  #define	OSIOCGIFMTU32	_IOWR('i', 126, struct netbsd32_oifreq)	/* get ifnet mtu */
 +
 +#define SIOCGIFDATA32	_IOWR('i', 133, struct netbsd32_ifdatareq)
 +#define SIOCZIFDATA32	_IOWR('i', 134, struct netbsd32_ifdatareq)
 +
  /* was 125 SIOCSIFASYNCMAP32 */
  /* was 124 SIOCGIFASYNCMAP32 */
  /* from <net/bpf.h> */
 


Home | Main Index | Thread Index | Old Index