xref: /illumos-gate/usr/src/uts/common/netinet/if_ether.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1982, 1986 Regents of the University of California.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms are permitted
11  * provided that this notice is preserved and that due credit is given
12  * to the University of California at Berkeley. The name of the University
13  * may not be used to endorse or promote products derived from this
14  * software without specific prior written permission. This software
15  * is provided ``as is'' without express or implied warranty.
16  */
17 
18 #ifndef	_NETINET_IF_ETHER_H
19 #define	_NETINET_IF_ETHER_H
20 
21 #pragma ident	"%Z%%M%	%I%	%E% SMI"
22 /* if_ether.h 1.28 89/08/04 SMI; from UCB 7.2 12/7/87 */
23 
24 #include <sys/ethernet.h>
25 
26 /*
27  * The following include is for compatibility with SunOS 3.x and
28  * 4.3bsd.  Newly written programs should include it separately.
29  */
30 #include <net/if_arp.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Ethernet Address Resolution Protocol.
38  *
39  * See RFC 826 for protocol description.  Structure below is adapted
40  * to resolving internet addresses.  Field names used correspond to
41  * RFC 826.
42  */
43 struct	ether_arp {
44 	struct	arphdr ea_hdr;		/* fixed-size header */
45 	ether_addr_t arp_sha;		/* sender hardware address */
46 	uchar_t	arp_spa[4];		/* sender protocol address */
47 	ether_addr_t arp_tha;		/* target hardware address */
48 	uchar_t	arp_tpa[4];		/* target protocol address */
49 };
50 #define	arp_hrd	ea_hdr.ar_hrd
51 #define	arp_pro	ea_hdr.ar_pro
52 #define	arp_hln	ea_hdr.ar_hln
53 #define	arp_pln	ea_hdr.ar_pln
54 #define	arp_op	ea_hdr.ar_op
55 
56 /*
57  *	multicast address structure
58  *
59  *	Keep a reference count for each multicast address so
60  *	addresses loaded into chip are unique.
61  */
62 struct	mcaddr {
63 	struct	ether_addr	mc_enaddr;	/* multicast address */
64 	ushort_t mc_count;			/* reference count */
65 };
66 #define	MCADDRMAX	64		/* multicast addr table length */
67 #define	MCCOUNTMAX	4096		/* multicast addr max reference count */
68 
69 /*
70  * Structure shared between the ethernet driver modules and
71  * the address resolution code.  For example, each ec_softc or il_softc
72  * begins with this structure.
73  *
74  * The structure contains a pointer to an array of multicast addresses.
75  * This pointer is NULL until the first successful SIOCADDMULTI ioctl
76  * is issued for the interface.
77  */
78 struct	arpcom {
79 	struct	ifnet ac_if;		/* network-visible interface */
80 	struct	ether_addr ac_enaddr;	/* ethernet hardware address */
81 	struct	in_addr ac_ipaddr;	/* copy of ip address- XXX */
82 	struct	mcaddr *ac_mcaddr;	/* table of multicast addrs */
83 	ushort_t ac_nmcaddr;		/* count of M/C addrs in use */
84 	struct  in_addr ac_lastip;	/* cache of last ARP lookup */
85 	struct	ether_addr ac_lastarp;	/* result of the last ARP */
86 };
87 
88 /*
89  * Internet to ethernet address resolution table.
90  */
91 struct	arptab {
92 	struct	in_addr at_iaddr;	/* internet address */
93 	union {
94 	    struct ether_addr atu_enaddr;	/* ethernet address */
95 	    long   atu_tvsec;			/* timestamp if incomplete */
96 	} 	at_union;
97 	uchar_t	at_timer;		/* minutes since last reference */
98 	uchar_t	at_flags;		/* flags */
99 	struct	mbuf *at_hold;		/* last packet until resolved/timeout */
100 };
101 
102 #define	at_enaddr	at_union.atu_enaddr
103 #define	at_tvsec	at_union.atu_tvsec
104 
105 /*
106  * Copy IP addresses from a to b - assumes that the two given
107  * pointers can be referenced as shorts.  On architectures
108  * where this is not the case, use bcopy instead.
109  */
110 #if defined(__sparc) || defined(__i386) || defined(__amd64)
111 #define	ip_copy(a, b) { ((short *)b)[0] = ((short *)a)[0]; \
112 	((short *)b)[1] = ((short *)a)[1]; }
113 #else
114 #define	ip_copy(a, b) (bcopy((caddr_t)a, (caddr_t)b, 4))
115 #endif
116 
117 #ifdef	__cplusplus
118 }
119 #endif
120 
121 #endif	/* _NETINET_IF_ETHER_H */
122