1/*	$NetBSD$	*/
2
3/*-
4 * Copyright (c) 1982, 1986, 1990, 1993, 1994
5 *	The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 *    may be used to endorse or promote products derived from this software
17 *    without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifndef _COMPAT_SYS_SOCKIO_H_
33#define	_COMPAT_SYS_SOCKIO_H_
34
35#ifdef _KERNEL_OPT
36
37#include "opt_compat_netbsd.h"
38#include "opt_modular.h"
39
40#include <sys/ioccom.h>
41
42#if defined(COMPAT_09) || defined(COMPAT_10) || defined(COMPAT_11) || \
43    defined(COMPAT_12) || defined(COMPAT_13) || defined(COMPAT_14) || \
44    defined(COMPAT_15) || defined(COMPAT_16) || defined(COMPAT_20) || \
45    defined(COMPAT_30) || defined(COMPAT_40) || defined(MODULAR)
46#define COMPAT_OIFREQ
47#endif
48
49#if defined(COMPAT_09) || defined(COMPAT_10) || defined(COMPAT_11) || \
50    defined(COMPAT_12) || defined(COMPAT_13) || defined(COMPAT_14) || \
51    defined(COMPAT_15) || defined(COMPAT_16) || defined(COMPAT_20) || \
52    defined(COMPAT_30) || defined(COMPAT_40) || defined(COMPAT_50) || \
53    defined(MODULAR)
54#define COMPAT_OIFDATA
55#endif
56
57#endif /* _KERNEL_OPT */
58
59struct oifreq {
60	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
61	union {
62		struct	sockaddr ifru_addr;
63		struct	sockaddr ifru_dstaddr;
64		struct	sockaddr ifru_broadaddr;
65		short	ifru_flags;
66		int	ifru_metric;
67		int	ifru_mtu;
68		int	ifru_dlt;
69		u_int	ifru_value;
70		void *	ifru_data;
71		struct {
72			uint32_t	b_buflen;
73			void		*b_buf;
74		} ifru_b;
75	} ifr_ifru;
76};
77struct	oifconf {
78	int	ifc_len;		/* size of associated buffer */
79	union {
80		void *	ifcu_buf;
81		struct	oifreq *ifcu_req;
82	} ifc_ifcu;
83#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
84#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
85};
86
87#include <compat/sys/time.h>
88/*
89 * Structure defining statistics and other data kept regarding a network
90 * interface.
91 */
92struct oif_data {
93	/* generic interface information */
94	u_char	ifi_type;		/* ethernet, tokenring, etc. */
95	u_char	ifi_addrlen;		/* media address length */
96	u_char	ifi_hdrlen;		/* media header length */
97	int	ifi_link_state;		/* current link state */
98	u_quad_t ifi_mtu;		/* maximum transmission unit */
99	u_quad_t ifi_metric;		/* routing metric (external only) */
100	u_quad_t ifi_baudrate;		/* linespeed */
101	/* volatile statistics */
102	u_quad_t ifi_ipackets;		/* packets received on interface */
103	u_quad_t ifi_ierrors;		/* input errors on interface */
104	u_quad_t ifi_opackets;		/* packets sent on interface */
105	u_quad_t ifi_oerrors;		/* output errors on interface */
106	u_quad_t ifi_collisions;	/* collisions on csma interfaces */
107	u_quad_t ifi_ibytes;		/* total number of octets received */
108	u_quad_t ifi_obytes;		/* total number of octets sent */
109	u_quad_t ifi_imcasts;		/* packets received via multicast */
110	u_quad_t ifi_omcasts;		/* packets sent via multicast */
111	u_quad_t ifi_iqdrops;		/* dropped on input, this interface */
112	u_quad_t ifi_noproto;		/* destined for unsupported protocol */
113	struct	timeval50 ifi_lastchange;/* last operational state change */
114};
115
116struct oifdatareq {
117	char	ifdr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
118	struct	oif_data ifdr_data;
119};
120
121#define	OSIOCSIFADDR	 _IOW('i', 12, struct oifreq)	/* set ifnet address */
122#define	OOSIOCGIFADDR	 _IOWR('i', 13, struct oifreq)	/* get ifnet address */
123#define	OSIOCSIFDSTADDR	 _IOW('i', 14, struct oifreq)	/* set p-p address */
124#define	OOSIOCGIFDSTADDR _IOWR('i', 15, struct oifreq)	/* get p-p address */
125#define OSIOCSIFFLAGS    _IOW('i', 16, struct oifreq)	/* set ifnet flags */
126#define	OSIOCGIFFLAGS    _IOWR('i', 17, struct oifreq)	/* get ifnet flags */
127#define	OOSIOCGIFBRDADDR _IOWR('i', 18, struct oifreq)	/* get bcast addr */
128#define	OSIOCSIFBRDADDR	 _IOW('i', 19, struct oifreq)	/* set bcast addr */
129#define	OOSIOCGIFCONF	 _IOWR('i', 20, struct ifconf)	/* get ifnet list */
130#define	OOSIOCGIFNETMASK _IOWR('i', 21, struct oifreq)	/* get net addr mask */
131#define	OSIOCSIFNETMASK	 _IOW('i', 22, struct oifreq)	/* set net addr mask */
132#define	OSIOCGIFCONF	 _IOWR('i', 36, struct ifconf)	/* get ifnet list */
133#define	OSIOCADDMULTI	 _IOW('i', 49, struct oifreq)	/* add m'cast addr */
134#define	OSIOCDELMULTI	 _IOW('i', 50, struct oifreq)	/* del m'cast addr */
135#define	OSIOCSIFMEDIA	 _IOWR('i', 53, struct oifreq)	/* set net media */
136#define	OSIOCGIFMTU	 _IOWR('i', 126, struct oifreq)	/* get ifnet mtu */
137#define	OSIOCGIFDATA	 _IOWR('i', 128, struct oifdatareq) /* get if_data */
138#define	OSIOCZIFDATA	 _IOWR('i', 129, struct oifdatareq) /* get if_data then
139							     zero ctrs*/
140
141
142
143
144#define	OBIOCGETIF	 _IOR('B', 107, struct oifreq)
145#define	OBIOCSETIF	 _IOW('B', 108, struct oifreq)
146#define	OTAPGIFNAME	 _IOR('e', 0, struct oifreq)
147
148#define ifreqn2o(oi, ni) \
149	do { \
150		(void)memcpy((oi)->ifr_name, (ni)->ifr_name, \
151		    sizeof((oi)->ifr_name)); \
152		(void)memcpy(&(oi)->ifr_ifru, &(ni)->ifr_ifru, \
153		    sizeof((oi)->ifr_ifru)); \
154	} while (/*CONSTCOND*/0)
155
156#define ifreqo2n(oi, ni) \
157	do { \
158		(void)memcpy((ni)->ifr_name, (oi)->ifr_name, \
159		    sizeof((oi)->ifr_name)); \
160		(void)memcpy(&(ni)->ifr_ifru, &(oi)->ifr_ifru, \
161		    sizeof((oi)->ifr_ifru)); \
162	} while (/*CONSTCOND*/0)
163
164#define ifdatan2o(oi, ni) \
165	do { \
166		(void)memcpy((oi), (ni),  sizeof(*(oi))); \
167		(oi)->ifi_lastchange.tv_sec = \
168		    (int32_t)(ni)->ifi_lastchange.tv_sec; \
169		(oi)->ifi_lastchange.tv_usec = \
170		    (ni)->ifi_lastchange.tv_nsec / 1000; \
171	} while (/*CONSTCOND*/0)
172
173#define ifdatao2n(oi, ni) \
174	do { \
175		(void)memcpy((ni), (oi),  sizeof(*(oi))); \
176		    sizeof((oi)->ifr_name)); \
177		(ni)->ifi_lastchange.tv_sec = (oi)->ifi_lastchange.tv_sec; \
178		(ni)->ifi_lastchange.tv_nsec = \
179		    (oi)->ifi_lastchange.tv_usec * 1000; \
180	} while (/*CONSTCOND*/0)
181#ifdef _KERNEL
182__BEGIN_DECLS
183int compat_ifconf(u_long, void *);
184int compat_ifdatareq(struct lwp *, u_long, void *);
185__END_DECLS
186#endif
187#endif /* _COMPAT_SYS_SOCKIO_H_ */
188