if_ether.h revision 60833
152419Sjulian/* $NetBSD: if_ether.h,v 1.25 1997/01/17 17:06:06 mikel Exp $ */ 252419Sjulian 352419Sjulian/* 452419Sjulian * Copyright (c) 1982, 1986, 1993 552419Sjulian * The Regents of the University of California. All rights reserved. 652419Sjulian * 752419Sjulian * Redistribution and use in source and binary forms, with or without 852419Sjulian * modification, are permitted provided that the following conditions 952419Sjulian * are met: 1052419Sjulian * 1. Redistributions of source code must retain the above copyright 1152419Sjulian * notice, this list of conditions and the following disclaimer. 1252419Sjulian * 2. Redistributions in binary form must reproduce the above copyright 1352419Sjulian * notice, this list of conditions and the following disclaimer in the 1452419Sjulian * documentation and/or other materials provided with the distribution. 1552419Sjulian * 3. All advertising materials mentioning features or use of this software 1652419Sjulian * must display the following acknowledgement: 1752419Sjulian * This product includes software developed by the University of 1852419Sjulian * California, Berkeley and its contributors. 1952419Sjulian * 4. Neither the name of the University nor the names of its contributors 2052419Sjulian * may be used to endorse or promote products derived from this software 2152419Sjulian * without specific prior written permission. 2252419Sjulian * 2352419Sjulian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2452419Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2552419Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2652419Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2752419Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2852419Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2952419Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3052419Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3152419Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3252419Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3352419Sjulian * SUCH DAMAGE. 3452419Sjulian * 3552419Sjulian * @(#)if_ether.h 8.1 (Berkeley) 6/10/93 3652419Sjulian * 3752419Sjulian * $FreeBSD: head/lib/libstand/if_ether.h 60833 2000-05-23 20:41:01Z jake $ 3853913Sarchie */ 3952419Sjulian 4052419Sjulian/* 4152419Sjulian * Ethernet address - 6 octets 4252419Sjulian * this is only used by the ethers(3) functions. 4353913Sarchie */ 4453913Sarchiestruct ether_addr { 4553913Sarchie u_int8_t ether_addr_octet[6]; 4653913Sarchie}; 4752419Sjulian 4852419Sjulian/* 4952419Sjulian * Structure of a 10Mb/s Ethernet header. 5052419Sjulian */ 5152419Sjulian#define ETHER_ADDR_LEN 6 5252419Sjulian 5352419Sjulianstruct ether_header { 5453913Sarchie u_int8_t ether_dhost[ETHER_ADDR_LEN]; 5552419Sjulian u_int8_t ether_shost[ETHER_ADDR_LEN]; 5652419Sjulian u_int16_t ether_type; 5752419Sjulian}; 5852419Sjulian 5952419Sjulian#define ETHERTYPE_PUP 0x0200 /* PUP protocol */ 6052419Sjulian#define ETHERTYPE_IP 0x0800 /* IP protocol */ 6152419Sjulian#define ETHERTYPE_ARP 0x0806 /* address resolution protocol */ 6262471Sphk#define ETHERTYPE_REVARP 0x8035 /* reverse addr resolution protocol */ 6352419Sjulian 6452419Sjulian/* 6552419Sjulian * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have 6652419Sjulian * (type-ETHERTYPE_TRAIL)*512 bytes of data followed 6752419Sjulian * by an ETHER type (as given above) and then the (variable-length) header. 6853913Sarchie */ 6952419Sjulian#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ 7052419Sjulian#define ETHERTYPE_NTRAILER 16 7152419Sjulian 7252419Sjulian#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ 7352419Sjulian 7452419Sjulian#define ETHERMTU 1500 7552419Sjulian#define ETHERMIN (60-14) 7652419Sjulian 7752419Sjulian#ifdef _KERNEL 7852419Sjulian/* 7952419Sjulian * Macro to map an IP multicast address to an Ethernet multicast address. 8052419Sjulian * The high-order 25 bits of the Ethernet address are statically assigned, 8152419Sjulian * and the low-order 23 bits are taken from the low end of the IP address. 8252419Sjulian */ 8352419Sjulian#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ 8452419Sjulian /* struct in_addr *ipaddr; */ \ 8553913Sarchie /* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \ 8653913Sarchie{ \ 8752419Sjulian (enaddr)[0] = 0x01; \ 8852419Sjulian (enaddr)[1] = 0x00; \ 8952419Sjulian (enaddr)[2] = 0x5e; \ 9052419Sjulian (enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f; \ 9152419Sjulian (enaddr)[4] = ((u_int8_t *)ipaddr)[2]; \ 9253913Sarchie (enaddr)[5] = ((u_int8_t *)ipaddr)[3]; \ 9353913Sarchie} 9452419Sjulian#endif 9552419Sjulian 9652419Sjulian/* 9752419Sjulian * Ethernet Address Resolution Protocol. 9852419Sjulian * 9953913Sarchie * See RFC 826 for protocol description. Structure below is adapted 10053913Sarchie * to resolving internet addresses. Field names used correspond to 10152419Sjulian * RFC 826. 10252419Sjulian */ 10352419Sjulianstruct ether_arp { 10452419Sjulian struct arphdr ea_hdr; /* fixed-size header */ 10552419Sjulian u_int8_t arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */ 10652419Sjulian u_int8_t arp_spa[4]; /* sender protocol address */ 10752419Sjulian u_int8_t arp_tha[ETHER_ADDR_LEN]; /* target hardware address */ 10852419Sjulian u_int8_t arp_tpa[4]; /* target protocol address */ 10952419Sjulian}; 11052419Sjulian#define arp_hrd ea_hdr.ar_hrd 11152419Sjulian#define arp_pro ea_hdr.ar_pro 11252419Sjulian#define arp_hln ea_hdr.ar_hln 11352419Sjulian#define arp_pln ea_hdr.ar_pln 11452419Sjulian#define arp_op ea_hdr.ar_op 11552419Sjulian 11652419Sjulian/* 11752419Sjulian * Structure shared between the ethernet driver modules and 11852419Sjulian * the address resolution code. For example, each ec_softc or il_softc 11952419Sjulian * begins with this structure. 12052419Sjulian */ 12152419Sjulianstruct arpcom { 12252419Sjulian struct ifnet ac_if; /* network-visible interface */ 12352419Sjulian u_int8_t ac_enaddr[ETHER_ADDR_LEN]; /* ethernet hardware address */ 12452419Sjulian char ac__pad[2]; /* be nice to m68k ports */ 12552419Sjulian LIST_HEAD(, struct ether_multi) ac_multiaddrs; /* list of ether multicast addrs */ 12652419Sjulian int ac_multicnt; /* length of ac_multiaddrs list */ 12752419Sjulian}; 12852419Sjulian 12952419Sjulianstruct llinfo_arp { 13052419Sjulian LIST_ENTRY(struct llinfo_arp) la_list; 13152419Sjulian struct rtentry *la_rt; 13252419Sjulian struct mbuf *la_hold; /* last packet until resolved/timeout */ 13352419Sjulian long la_asked; /* last time we QUERIED for this addr */ 13452419Sjulian#define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */ 13552419Sjulian}; 13652419Sjulian 13752419Sjulianstruct sockaddr_inarp { 13852419Sjulian u_int8_t sin_len; 13952419Sjulian u_int8_t sin_family; 14052419Sjulian u_int16_t sin_port; 14152419Sjulian struct in_addr sin_addr; 14252419Sjulian struct in_addr sin_srcaddr; 14352419Sjulian u_int16_t sin_tos; 14452419Sjulian u_int16_t sin_other; 14556709Sarchie#define SIN_PROXY 1 14652419Sjulian}; 14752419Sjulian 14852419Sjulian/* 14952419Sjulian * IP and ethernet specific routing flags 15052419Sjulian */ 15152419Sjulian#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */ 15252419Sjulian#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */ 15352419Sjulian 15452419Sjulian#ifdef _KERNEL 15552419Sjulianu_int8_t etherbroadcastaddr[ETHER_ADDR_LEN]; 15652419Sjulianu_int8_t ether_ipmulticast_min[ETHER_ADDR_LEN]; 15752419Sjulianu_int8_t ether_ipmulticast_max[ETHER_ADDR_LEN]; 15852419Sjulianstruct ifqueue arpintrq; 15952419Sjulian 16052419Sjulianvoid arpwhohas(struct arpcom *, struct in_addr *); 16152419Sjulianvoid arpintr(void); 16252419Sjulianint arpresolve(struct arpcom *, 16352419Sjulian struct rtentry *, struct mbuf *, struct sockaddr *, u_char *); 16452419Sjulianvoid arp_ifinit(struct arpcom *, struct ifaddr *); 16552419Sjulianvoid arp_rtrequest(int, struct rtentry *, struct sockaddr *); 16652419Sjulian 16752419Sjulianint ether_addmulti(struct ifreq *, struct arpcom *); 16852419Sjulianint ether_delmulti(struct ifreq *, struct arpcom *); 16952419Sjulian#endif /* _KERNEL */ 17052419Sjulian 17152419Sjulian/* 17252419Sjulian * Ethernet multicast address structure. There is one of these for each 17352419Sjulian * multicast address or range of multicast addresses that we are supposed 17452419Sjulian * to listen to on a particular interface. They are kept in a linked list, 17552419Sjulian * rooted in the interface's arpcom structure. (This really has nothing to 17652419Sjulian * do with ARP, or with the Internet address family, but this appears to be 17752419Sjulian * the minimally-disrupting place to put it.) 17852419Sjulian */ 17952419Sjulianstruct ether_multi { 18052419Sjulian u_int8_t enm_addrlo[ETHER_ADDR_LEN]; /* low or only address of range */ 18152419Sjulian u_int8_t enm_addrhi[ETHER_ADDR_LEN]; /* high or only address of range */ 18252419Sjulian struct arpcom *enm_ac; /* back pointer to arpcom */ 18352419Sjulian u_int enm_refcount; /* no. claims to this addr/range */ 18452419Sjulian LIST_ENTRY(struct ether_multi) enm_list; 18552419Sjulian}; 18652419Sjulian 18752419Sjulian/* 18852419Sjulian * Structure used by macros below to remember position when stepping through 18952419Sjulian * all of the ether_multi records. 19052419Sjulian */ 19152419Sjulianstruct ether_multistep { 19252419Sjulian struct ether_multi *e_enm; 19352419Sjulian}; 19452419Sjulian 19552419Sjulian/* 19652419Sjulian * Macro for looking up the ether_multi record for a given range of Ethernet 19752419Sjulian * multicast addresses connected to a given arpcom structure. If no matching 19852419Sjulian * record is found, "enm" returns NULL. 19952419Sjulian */ 20052419Sjulian#define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \ 20152419Sjulian /* u_int8_t addrlo[ETHER_ADDR_LEN]; */ \ 20253913Sarchie /* u_int8_t addrhi[ETHER_ADDR_LEN]; */ \ 20352419Sjulian /* struct arpcom *ac; */ \ 20452419Sjulian /* struct ether_multi *enm; */ \ 20553913Sarchie{ \ 20653913Sarchie for ((enm) = (ac)->ac_multiaddrs.lh_first; \ 20753913Sarchie (enm) != NULL && \ 20853913Sarchie (bcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 || \ 20953913Sarchie bcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \ 21053913Sarchie (enm) = (enm)->enm_list.le_next); \ 21153913Sarchie} 21253913Sarchie 21353913Sarchie/* 21453913Sarchie * Macro to step through all of the ether_multi records, one at a time. 21553913Sarchie * The current position is remembered in "step", which the caller must 21653913Sarchie * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step" 21753913Sarchie * and get the first record. Both macros return a NULL "enm" when there 21853913Sarchie * are no remaining records. 21953913Sarchie */ 22053913Sarchie#define ETHER_NEXT_MULTI(step, enm) \ 22153913Sarchie /* struct ether_multistep step; */ \ 22253913Sarchie /* struct ether_multi *enm; */ \ 22353913Sarchie{ \ 22453913Sarchie if (((enm) = (step).e_enm) != NULL) \ 22553913Sarchie (step).e_enm = (enm)->enm_list.le_next; \ 22653913Sarchie} 22753913Sarchie 22853913Sarchie#define ETHER_FIRST_MULTI(step, ac, enm) \ 22953913Sarchie /* struct ether_multistep step; */ \ 23053913Sarchie /* struct arpcom *ac; */ \ 23153913Sarchie /* struct ether_multi *enm; */ \ 23261880Sarchie{ \ 23361880Sarchie (step).e_enm = (ac)->ac_multiaddrs.lh_first; \ 23453913Sarchie ETHER_NEXT_MULTI((step), (enm)); \ 23553913Sarchie} 23661880Sarchie 23753913Sarchie#ifdef _KERNEL 23853913Sarchievoid arp_rtrequest(int, struct rtentry *, struct sockaddr *); 23953913Sarchieint arpresolve(struct arpcom *, struct rtentry *, struct mbuf *, 24053913Sarchie struct sockaddr *, u_char *); 24153913Sarchievoid arpintr(void); 24253913Sarchieint arpioctl(u_long, caddr_t); 24353913Sarchievoid arp_ifinit(struct arpcom *, struct ifaddr *); 24461880Sarchievoid revarpinput(struct mbuf *); 24553913Sarchievoid in_revarpinput(struct mbuf *); 24653913Sarchievoid revarprequest(struct ifnet *); 24753913Sarchieint revarpwhoarewe(struct ifnet *, struct in_addr *, struct in_addr *); 24853913Sarchieint revarpwhoami(struct in_addr *, struct ifnet *); 24953913Sarchieint db_show_arptab(void); 25053913Sarchie#endif 25153913Sarchie 25253913Sarchie/* 25353913Sarchie * Prototype ethers(3) functions. 25453913Sarchie */ 25553913Sarchie#ifndef _KERNEL 25653913Sarchie#include <sys/cdefs.h> 25753913Sarchie__BEGIN_DECLS 25853913Sarchiechar * ether_ntoa(struct ether_addr *); 25953913Sarchiestruct ether_addr * 26053913Sarchie ether_aton(char *); 26153913Sarchieint ether_ntohost(char *, struct ether_addr *); 26253913Sarchieint ether_hostton(char *, struct ether_addr *); 26353913Sarchieint ether_line(char *, struct ether_addr *, char *); 26453913Sarchie__END_DECLS 26552419Sjulian#endif 26652419Sjulian