xref: /haiku/src/libs/compat/freebsd_network/compat/net/if.h (revision 97f11716bfaa0f385eb0e28a52bf56a5023b9e99)
1 /*
2  * Copyright 2007, Hugo Santos. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _FBSD_COMPAT_NET_IF_H_
6 #define _FBSD_COMPAT_NET_IF_H_
7 
8 
9 #include <posix/net/if.h>
10 
11 #include <sys/cdefs.h>
12 #include <sys/queue.h>
13 #include <sys/time.h>
14 
15 
16 #define IF_Kbps(x)				((uintmax_t)(x) * 1000)
17 #define IF_Mbps(x)				(IF_Kbps((x) * 1000))
18 #define IF_Gbps(x)				(IF_Mbps((x) * 1000))
19 
20 /* Capabilities that interfaces can advertise. */
21 #define	IFCAP_RXCSUM		0x00001  /* can offload checksum on RX */
22 #define	IFCAP_TXCSUM		0x00002  /* can offload checksum on TX */
23 #define	IFCAP_NETCONS		0x00004  /* can be a network console */
24 #define	IFCAP_VLAN_MTU		0x00008	/* VLAN-compatible MTU */
25 #define	IFCAP_VLAN_HWTAGGING	0x00010	/* hardware VLAN tag support */
26 #define	IFCAP_JUMBO_MTU		0x00020	/* 9000 byte MTU supported */
27 #define	IFCAP_POLLING		0x00040	/* driver supports polling */
28 #define	IFCAP_VLAN_HWCSUM	0x00080	/* can do IFCAP_HWCSUM on VLANs */
29 #define	IFCAP_TSO4		0x00100	/* can do TCP Segmentation Offload */
30 #define	IFCAP_TSO6		0x00200	/* can do TCP6 Segmentation Offload */
31 #define	IFCAP_LRO		0x00400	/* can do Large Receive Offload */
32 #define	IFCAP_WOL_UCAST		0x00800	/* wake on any unicast frame */
33 #define	IFCAP_WOL_MCAST		0x01000	/* wake on any multicast frame */
34 #define	IFCAP_WOL_MAGIC		0x02000	/* wake on any Magic Packet */
35 #define	IFCAP_TOE4		0x04000	/* interface can offload TCP */
36 #define	IFCAP_TOE6		0x08000	/* interface can offload TCP6 */
37 #define	IFCAP_VLAN_HWFILTER	0x10000 /* interface hw can filter vlan tag */
38 /* 	available		0x20000 */
39 #define	IFCAP_VLAN_HWTSO	0x40000 /* can do IFCAP_TSO on VLANs */
40 #define	IFCAP_LINKSTATE		0x80000 /* the runtime link state is dynamic */
41 #define	IFCAP_NETMAP		0x100000 /* netmap mode supported/enabled */
42 #define	IFCAP_RXCSUM_IPV6	0x200000  /* can offload checksum on IPv6 RX */
43 #define	IFCAP_TXCSUM_IPV6	0x400000  /* can offload checksum on IPv6 TX */
44 #define	IFCAP_HWSTATS		0x800000 /* manages counters internally */
45 #define	IFCAP_TXRTLMT		0x1000000 /* hardware supports TX rate limiting */
46 #define	IFCAP_HWRXTSTMP		0x2000000 /* hardware rx timestamping */
47 #define	IFCAP_MEXTPG		0x4000000 /* understands M_EXTPG mbufs */
48 #define	IFCAP_TXTLS4		0x8000000 /* can do TLS encryption and segmentation for TCP */
49 #define	IFCAP_TXTLS6		0x10000000 /* can do TLS encryption and segmentation for TCP6 */
50 #define	IFCAP_VXLAN_HWCSUM	0x20000000 /* can do IFCAN_HWCSUM on VXLANs */
51 #define	IFCAP_VXLAN_HWTSO	0x40000000 /* can do IFCAP_TSO on VXLANs */
52 #define	IFCAP_TXTLS_RTLMT	0x80000000 /* can do TLS with rate limiting */
53 
54 #define IFCAP_HWCSUM_IPV6	(IFCAP_RXCSUM_IPV6 | IFCAP_TXCSUM_IPV6)
55 
56 #define IFCAP_HWCSUM	(IFCAP_RXCSUM | IFCAP_TXCSUM)
57 #define	IFCAP_TSO	(IFCAP_TSO4 | IFCAP_TSO6)
58 #define	IFCAP_WOL	(IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC)
59 #define	IFCAP_TOE	(IFCAP_TOE4 | IFCAP_TOE6)
60 
61 #define	IFCAP_CANTCHANGE	(IFCAP_NETMAP)
62 
63 /* interface flags -- these extend the Haiku-native ones from posix/net/if.h */
64 #define IFF_DRV_RUNNING		0x00010000
65 #define IFF_DRV_OACTIVE		0x00020000
66 #define IFF_LINK0			0x00040000		/* per link layer defined bit */
67 #define	IFF_LINK1			0x00080000		/* per link layer defined bit */
68 #define	IFF_LINK2			0x00100000		/* per link layer defined bit */
69 #define IFF_DEBUG			0x00200000
70 #define	IFF_MONITOR			0x00400000		/* (n) user-requested monitor mode */
71 #define	IFF_PPROMISC		0x00800000		/* (n) user-requested promisc mode */
72 #define	IFF_NOGROUP			0x01000000		/* (n) interface is not part of any groups */
73 #define	IFF_NEEDSGIANT		0x02000000		/* (i) hold Giant over hook calls (OpenBSD compatibility) */
74 
75 #define LINK_STATE_UNKNOWN	0
76 #define LINK_STATE_DOWN		1
77 #define LINK_STATE_UP		2
78 
79 #define IFQ_MAXLEN			50
80 
81 
82 /*
83  * Structure describing information about an interface
84  * which may be of interest to management entities.
85  */
86 struct if_data {
87 	/* generic interface information */
88 	uint8_t	ifi_type;			/* ethernet, tokenring, etc */
89 	uint8_t	ifi_physical;		/* e.g., AUI, Thinnet, 10base-T, etc */
90 	uint8_t	ifi_addrlen;		/* media address length */
91 	uint8_t	ifi_hdrlen;			/* media header length */
92 	uint8_t	ifi_link_state;		/* current link state */
93 	uint8_t	ifi_recvquota;		/* polling quota for receive intrs */
94 	uint8_t	ifi_xmitquota;		/* polling quota for xmit intrs */
95 	uint16_t	ifi_datalen;		/* length of this data struct */
96 	uint32_t	ifi_mtu;			/* maximum transmission unit */
97 	uint32_t	ifi_metric;			/* routing metric (external only) */
98 	uint64_t	ifi_baudrate;		/* linespeed */
99 	/* volatile statistics */
100 	uint64_t	ifi_ipackets;		/* packets received on interface */
101 	uint64_t	ifi_ierrors;		/* input errors on interface */
102 	uint64_t	ifi_opackets;		/* packets sent on interface */
103 	uint64_t	ifi_oerrors;		/* output errors on interface */
104 	uint64_t	ifi_collisions;		/* collisions on csma interfaces */
105 	uint64_t	ifi_ibytes;			/* total number of octets received */
106 	uint64_t	ifi_obytes;			/* total number of octets sent */
107 	uint64_t	ifi_imcasts;		/* packets received via multicast */
108 	uint64_t	ifi_omcasts;		/* packets sent via multicast */
109 	uint64_t	ifi_iqdrops;		/* dropped on input, this interface */
110 	uint64_t	ifi_oqdrops;		/* dropped on output, this interface */
111 	uint64_t	ifi_noproto;		/* destined for unsupported protocol */
112 	uint64_t	ifi_hwassist;		/* HW offload capabilities */
113 	time_t	ifi_epoch;			/* uptime at attach or stat reset */
114 #ifdef __alpha__
115 	u_int	ifi_timepad;		/* time_t is int, not long on alpha */
116 #endif
117 	struct	timeval ifi_lastchange;	/* time of last administrative change */
118 };
119 
120 struct ifmediareq {
121 	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
122 	int	ifm_current;		/* current media options */
123 	int	ifm_mask;		/* don't care mask */
124 	int	ifm_status;		/* media status */
125 	int	ifm_active;		/* active options */
126 	int	ifm_count;		/* # entries in ifm_ulist array */
127 	int	*ifm_ulist;		/* media words */
128 };
129 
130 struct  ifdrv {
131 	char			ifd_name[IFNAMSIZ];     /* if name, e.g. "en0" */
132 	unsigned long	ifd_cmd;
133 	size_t			ifd_len;
134 	void*			ifd_data;
135 };
136 
137 /*
138  * Structure used to request i2c data
139  * from interface transceivers.
140  */
141 struct ifi2creq {
142 	uint8_t dev_addr;	/* i2c address (0xA0, 0xA2) */
143 	uint8_t offset;		/* read offset */
144 	uint8_t len;		/* read length */
145 	uint8_t spare0;
146 	uint32_t spare1;
147 	uint8_t data[8];	/* read buffer */
148 };
149 
150 #ifdef _KERNEL
151 /* TODO: this should go away soon. */
152 #	include <net/if_var.h>
153 #endif
154 
155 
156 #endif	/* _FBSD_COMPAT_NET_IF_H_ */
157