/*      $NetBSD: if.h,v 1.7 2022/09/28 15:32:09 msaitoh Exp $   */

/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by William Studenmund and Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the
*    documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/*
* Copyright (c) 1982, 1986, 1989, 1993
*      The Regents of the University of California.  All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the
*    documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
*    may be used to endorse or promote products derived from this software
*    without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*      @(#)if.h        8.3 (Berkeley) 2/9/95
*/

#ifndef _COMPAT_NET_IF_H_
#define _COMPAT_NET_IF_H_

#include <net/route.h>
#include <compat/sys/time.h>

#define OIFNAMSIZ       16

struct oifreq {
       char    ifr_name[OIFNAMSIZ];            /* if name, e.g. "en0" */
       union {
               struct  sockaddr ifru_addr;
               struct  sockaddr ifru_dstaddr;
               struct  sockaddr ifru_broadaddr;
               short   ifru_flags;
               int     ifru_metric;
               int     ifru_mtu;
               int     ifru_dlt;
               u_int   ifru_value;
               void *  ifru_data;
               struct {
                       uint32_t        b_buflen;
                       void            *b_buf;
               } ifru_b;
       } ifr_ifru;
};
struct  oifconf {
       int     ifc_len;                /* size of associated buffer */
       union {
               void *  ifcu_buf;
               struct  oifreq *ifcu_req;
       } ifc_ifcu;
#define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
#define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
};

/* Pre-1.5 if_data struct */
struct if_data14 {
       /* generic interface information */
       u_char  ifi_type;               /* ethernet, tokenring, etc. */
       u_char  ifi_addrlen;            /* media address length */
       u_char  ifi_hdrlen;             /* media header length */
       u_long  ifi_mtu;                /* maximum transmission unit */
       u_long  ifi_metric;             /* routing metric (external only) */
       u_long  ifi_baudrate;           /* linespeed */
       /* volatile statistics */
       u_long  ifi_ipackets;           /* packets received on interface */
       u_long  ifi_ierrors;            /* input errors on interface */
       u_long  ifi_opackets;           /* packets sent on interface */
       u_long  ifi_oerrors;            /* output errors on interface */
       u_long  ifi_collisions;         /* collisions on csma interfaces */
       u_long  ifi_ibytes;             /* total number of octets received */
       u_long  ifi_obytes;             /* total number of octets sent */
       u_long  ifi_imcasts;            /* packets received via multicast */
       u_long  ifi_omcasts;            /* packets sent via multicast */
       u_long  ifi_iqdrops;            /* dropped on input, this interface */
       u_long  ifi_noproto;            /* destined for unsupported protocol */
       struct  timeval50 ifi_lastchange;/* last operational state change */
};

/* pre-1.5 if_msghdr (ifm_data changed) */
struct if_msghdr14 {
       u_short ifm_msglen;     /* to skip over non-understood messages */
       u_char  ifm_version;    /* future binary compatibility */
       u_char  ifm_type;       /* message type */
       int     ifm_addrs;      /* like rtm_addrs */
       int     ifm_flags;      /* value of if_flags */
       u_short ifm_index;      /* index for associated ifp */
       struct  if_data14 ifm_data; /* statistics and other data about if */
};

void compat_14_rt_oifmsg(struct ifnet *);
int compat_14_iflist(struct ifnet *, struct rt_walkarg *, struct rt_addrinfo *,
   size_t);

/*
* Structure defining statistics and other data kept regarding a network
* interface.
*/
struct if_data50 {
       /* generic interface information */
       u_char  ifi_type;               /* ethernet, tokenring, etc. */
       u_char  ifi_addrlen;            /* media address length */
       u_char  ifi_hdrlen;             /* media header length */
       int     ifi_link_state;         /* current link state */
       uint64_t ifi_mtu;               /* maximum transmission unit */
       uint64_t ifi_metric;            /* routing metric (external only) */
       uint64_t ifi_baudrate;          /* linespeed */
       /* volatile statistics */
       uint64_t ifi_ipackets;          /* packets received on interface */
       uint64_t ifi_ierrors;           /* input errors on interface */
       uint64_t ifi_opackets;          /* packets sent on interface */
       uint64_t ifi_oerrors;           /* output errors on interface */
       uint64_t ifi_collisions;        /* collisions on csma interfaces */
       uint64_t ifi_ibytes;            /* total number of octets received */
       uint64_t ifi_obytes;            /* total number of octets sent */
       uint64_t ifi_imcasts;           /* packets received via multicast */
       uint64_t ifi_omcasts;           /* packets sent via multicast */
       uint64_t ifi_iqdrops;           /* dropped on input, this interface */
       uint64_t ifi_noproto;           /* destined for unsupported protocol */
       struct  timeval50 ifi_lastchange;/* last operational state change */
};

/*
* Structure defining statistics and other data kept regarding a network
* interface.
*/
struct ifdatareq50 {
       char    ifdr_name[OIFNAMSIZ];           /* if name, e.g. "en0" */
       struct  if_data50 ifdr_data;
};

/*
* Message format for use in obtaining information about interfaces
* from sysctl and the routing socket.
*/
struct if_msghdr50 {
       u_short ifm_msglen;     /* to skip over non-understood messages */
       u_char  ifm_version;    /* future binary compatibility */
       u_char  ifm_type;       /* message type */
       int     ifm_addrs;      /* like rtm_addrs */
       int     ifm_flags;      /* value of if_flags */
       u_short ifm_index;      /* index for associated ifp */
       struct  if_data50 ifm_data;/* statistics and other data about if */
};

void compat_50_rt_oifmsg(struct ifnet *);
int compat_50_iflist(struct ifnet *, struct rt_walkarg *, struct rt_addrinfo *,
   size_t);

/*
* Message format for use in obtaining information about interface addresses
* from sysctl and the routing socket.
*/
struct ifa_msghdr50 {
       u_short ifam_msglen;    /* to skip over non-understood messages */
       u_char  ifam_version;   /* future binary compatibility */
       u_char  ifam_type;      /* message type */
       int     ifam_addrs;     /* like rtm_addrs */
       int     ifam_flags;     /* value of ifa_flags */
       u_short ifam_index;     /* index for associated ifp */
       int     ifam_metric;    /* value of ifa_metric */
};

/*
* Message format announcing the arrival or departure of a network interface.
*/
struct if_announcemsghdr50 {
       u_short ifan_msglen;    /* to skip over non-understood messages */
       u_char  ifan_version;   /* future binary compatibility */
       u_char  ifan_type;      /* message type */
       u_short ifan_index;     /* index for associated ifp */
       char    ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
       u_short ifan_what;      /* what type of announcement */
};

#if !defined(_KERNEL) || !defined(COMPAT_RTSOCK)
#define __align64       __aligned(sizeof(uint64_t))
#else
#define __align64
#endif
/*
* Message format for use in obtaining information about interface addresses
* from sysctl and the routing socket.
*/
struct ifa_msghdr70 {
       u_short ifam_msglen __align64;
                               /* to skip over non-understood messages */
       u_char  ifam_version;   /* future binary compatibility */
       u_char  ifam_type;      /* message type */
       int     ifam_addrs;     /* like rtm_addrs */
       int     ifam_flags;     /* value of ifa_flags */
       int     ifam_metric;    /* value of ifa_metric */
       u_short ifam_index;     /* index for associated ifp */
};
#undef __align64

int compat_70_iflist_addr(struct rt_walkarg *, struct ifaddr *,
   struct rt_addrinfo *);

#endif /* _COMPAT_NET_IF_H_ */