138451Smsmith/* $NetBSD: if_ether.h,v 1.25 1997/01/17 17:06:06 mikel Exp $ */ 238451Smsmith 338451Smsmith/* 438451Smsmith * Copyright (c) 1982, 1986, 1993 538451Smsmith * The Regents of the University of California. All rights reserved. 638451Smsmith * 738451Smsmith * Redistribution and use in source and binary forms, with or without 838451Smsmith * modification, are permitted provided that the following conditions 938451Smsmith * are met: 1038451Smsmith * 1. Redistributions of source code must retain the above copyright 1138451Smsmith * notice, this list of conditions and the following disclaimer. 1238451Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1338451Smsmith * notice, this list of conditions and the following disclaimer in the 1438451Smsmith * documentation and/or other materials provided with the distribution. 1538451Smsmith * 4. Neither the name of the University nor the names of its contributors 1638451Smsmith * may be used to endorse or promote products derived from this software 1738451Smsmith * without specific prior written permission. 1838451Smsmith * 1938451Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2038451Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2138451Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2238451Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2338451Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2438451Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2538451Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2638451Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2738451Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2838451Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2938451Smsmith * SUCH DAMAGE. 3038451Smsmith * 3138451Smsmith * @(#)if_ether.h 8.1 (Berkeley) 6/10/93 3260833Sjake * 3360833Sjake * $FreeBSD$ 3438451Smsmith */ 3538451Smsmith 3638451Smsmith/* 3738451Smsmith * Ethernet address - 6 octets 3838451Smsmith * this is only used by the ethers(3) functions. 3938451Smsmith */ 4038451Smsmithstruct ether_addr { 4138451Smsmith u_int8_t ether_addr_octet[6]; 4238451Smsmith}; 4338451Smsmith 4438451Smsmith/* 4538451Smsmith * Structure of a 10Mb/s Ethernet header. 4638451Smsmith */ 4738451Smsmith#define ETHER_ADDR_LEN 6 4838451Smsmith 4938451Smsmithstruct ether_header { 5038451Smsmith u_int8_t ether_dhost[ETHER_ADDR_LEN]; 5138451Smsmith u_int8_t ether_shost[ETHER_ADDR_LEN]; 5238451Smsmith u_int16_t ether_type; 5338451Smsmith}; 5438451Smsmith 5538451Smsmith#define ETHERTYPE_PUP 0x0200 /* PUP protocol */ 5638451Smsmith#define ETHERTYPE_IP 0x0800 /* IP protocol */ 5738451Smsmith#define ETHERTYPE_ARP 0x0806 /* address resolution protocol */ 5838451Smsmith#define ETHERTYPE_REVARP 0x8035 /* reverse addr resolution protocol */ 5938451Smsmith 6038451Smsmith/* 6138451Smsmith * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have 6238451Smsmith * (type-ETHERTYPE_TRAIL)*512 bytes of data followed 6338451Smsmith * by an ETHER type (as given above) and then the (variable-length) header. 6438451Smsmith */ 6538451Smsmith#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ 6638451Smsmith#define ETHERTYPE_NTRAILER 16 6738451Smsmith 6838451Smsmith#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ 6938451Smsmith 7038451Smsmith#define ETHERMTU 1500 7138451Smsmith#define ETHERMIN (60-14) 7238451Smsmith 7338451Smsmith#ifdef _KERNEL 7438451Smsmith/* 7538451Smsmith * Macro to map an IP multicast address to an Ethernet multicast address. 7638451Smsmith * The high-order 25 bits of the Ethernet address are statically assigned, 7738451Smsmith * and the low-order 23 bits are taken from the low end of the IP address. 7838451Smsmith */ 7938451Smsmith#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ 8038451Smsmith /* struct in_addr *ipaddr; */ \ 8138451Smsmith /* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \ 8238451Smsmith{ \ 8338451Smsmith (enaddr)[0] = 0x01; \ 8438451Smsmith (enaddr)[1] = 0x00; \ 8538451Smsmith (enaddr)[2] = 0x5e; \ 8638451Smsmith (enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f; \ 8738451Smsmith (enaddr)[4] = ((u_int8_t *)ipaddr)[2]; \ 8838451Smsmith (enaddr)[5] = ((u_int8_t *)ipaddr)[3]; \ 8938451Smsmith} 9038451Smsmith#endif 9138451Smsmith 9238451Smsmith/* 9338451Smsmith * Ethernet Address Resolution Protocol. 9438451Smsmith * 9538451Smsmith * See RFC 826 for protocol description. Structure below is adapted 9638451Smsmith * to resolving internet addresses. Field names used correspond to 9738451Smsmith * RFC 826. 9838451Smsmith */ 9938451Smsmithstruct ether_arp { 10038451Smsmith struct arphdr ea_hdr; /* fixed-size header */ 10138451Smsmith u_int8_t arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */ 10238451Smsmith u_int8_t arp_spa[4]; /* sender protocol address */ 10338451Smsmith u_int8_t arp_tha[ETHER_ADDR_LEN]; /* target hardware address */ 10438451Smsmith u_int8_t arp_tpa[4]; /* target protocol address */ 10538451Smsmith}; 10638451Smsmith#define arp_hrd ea_hdr.ar_hrd 10738451Smsmith#define arp_pro ea_hdr.ar_pro 10838451Smsmith#define arp_hln ea_hdr.ar_hln 10938451Smsmith#define arp_pln ea_hdr.ar_pln 11038451Smsmith#define arp_op ea_hdr.ar_op 11138451Smsmith 11238451Smsmith/* 11338451Smsmith * Structure shared between the ethernet driver modules and 11438451Smsmith * the address resolution code. For example, each ec_softc or il_softc 11538451Smsmith * begins with this structure. 11638451Smsmith */ 11738451Smsmithstruct arpcom { 11838451Smsmith struct ifnet ac_if; /* network-visible interface */ 11938451Smsmith u_int8_t ac_enaddr[ETHER_ADDR_LEN]; /* ethernet hardware address */ 12038451Smsmith char ac__pad[2]; /* be nice to m68k ports */ 12160938Sjake LIST_HEAD(, ether_multi) ac_multiaddrs; /* list of ether multicast addrs */ 12238451Smsmith int ac_multicnt; /* length of ac_multiaddrs list */ 12338451Smsmith}; 12438451Smsmith 12538451Smsmithstruct llinfo_arp { 12660938Sjake LIST_ENTRY(llinfo_arp) la_list; 12738451Smsmith struct rtentry *la_rt; 12838451Smsmith struct mbuf *la_hold; /* last packet until resolved/timeout */ 12938451Smsmith long la_asked; /* last time we QUERIED for this addr */ 13038451Smsmith#define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */ 13138451Smsmith}; 13238451Smsmith 13338451Smsmithstruct sockaddr_inarp { 13438451Smsmith u_int8_t sin_len; 13538451Smsmith u_int8_t sin_family; 13638451Smsmith u_int16_t sin_port; 13738451Smsmith struct in_addr sin_addr; 13838451Smsmith struct in_addr sin_srcaddr; 13938451Smsmith u_int16_t sin_tos; 14038451Smsmith u_int16_t sin_other; 14138451Smsmith#define SIN_PROXY 1 14238451Smsmith}; 14338451Smsmith 14438451Smsmith/* 14538451Smsmith * IP and ethernet specific routing flags 14638451Smsmith */ 14738451Smsmith#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */ 14838451Smsmith#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */ 14938451Smsmith 15038451Smsmith#ifdef _KERNEL 15138451Smsmithu_int8_t etherbroadcastaddr[ETHER_ADDR_LEN]; 15238451Smsmithu_int8_t ether_ipmulticast_min[ETHER_ADDR_LEN]; 15338451Smsmithu_int8_t ether_ipmulticast_max[ETHER_ADDR_LEN]; 15438451Smsmithstruct ifqueue arpintrq; 15538451Smsmith 15638451Smsmithvoid arpwhohas(struct arpcom *, struct in_addr *); 15738451Smsmithvoid arpintr(void); 15838451Smsmithint arpresolve(struct arpcom *, 159186119Sqingli struct rtentry *, struct mbuf *, struct sockaddr *, u_char *, struct llentry **); 16038451Smsmithvoid arp_ifinit(struct arpcom *, struct ifaddr *); 16138451Smsmithvoid arp_rtrequest(int, struct rtentry *, struct sockaddr *); 16238451Smsmith 16338451Smsmithint ether_addmulti(struct ifreq *, struct arpcom *); 16438451Smsmithint ether_delmulti(struct ifreq *, struct arpcom *); 16538451Smsmith#endif /* _KERNEL */ 16638451Smsmith 16738451Smsmith/* 16838451Smsmith * Ethernet multicast address structure. There is one of these for each 16938451Smsmith * multicast address or range of multicast addresses that we are supposed 17038451Smsmith * to listen to on a particular interface. They are kept in a linked list, 17138451Smsmith * rooted in the interface's arpcom structure. (This really has nothing to 17238451Smsmith * do with ARP, or with the Internet address family, but this appears to be 17338451Smsmith * the minimally-disrupting place to put it.) 17438451Smsmith */ 17538451Smsmithstruct ether_multi { 17638451Smsmith u_int8_t enm_addrlo[ETHER_ADDR_LEN]; /* low or only address of range */ 17738451Smsmith u_int8_t enm_addrhi[ETHER_ADDR_LEN]; /* high or only address of range */ 17838451Smsmith struct arpcom *enm_ac; /* back pointer to arpcom */ 17938451Smsmith u_int enm_refcount; /* no. claims to this addr/range */ 18060938Sjake LIST_ENTRY(ether_multi) enm_list; 18138451Smsmith}; 18238451Smsmith 18338451Smsmith/* 18438451Smsmith * Structure used by macros below to remember position when stepping through 18538451Smsmith * all of the ether_multi records. 18638451Smsmith */ 18738451Smsmithstruct ether_multistep { 18838451Smsmith struct ether_multi *e_enm; 18938451Smsmith}; 19038451Smsmith 19138451Smsmith/* 19238451Smsmith * Macro for looking up the ether_multi record for a given range of Ethernet 19338451Smsmith * multicast addresses connected to a given arpcom structure. If no matching 19438451Smsmith * record is found, "enm" returns NULL. 19538451Smsmith */ 19638451Smsmith#define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \ 19738451Smsmith /* u_int8_t addrlo[ETHER_ADDR_LEN]; */ \ 19838451Smsmith /* u_int8_t addrhi[ETHER_ADDR_LEN]; */ \ 19938451Smsmith /* struct arpcom *ac; */ \ 20038451Smsmith /* struct ether_multi *enm; */ \ 20138451Smsmith{ \ 20238451Smsmith for ((enm) = (ac)->ac_multiaddrs.lh_first; \ 20338451Smsmith (enm) != NULL && \ 20438451Smsmith (bcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 || \ 20538451Smsmith bcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \ 20638451Smsmith (enm) = (enm)->enm_list.le_next); \ 20738451Smsmith} 20838451Smsmith 20938451Smsmith/* 21038451Smsmith * Macro to step through all of the ether_multi records, one at a time. 21138451Smsmith * The current position is remembered in "step", which the caller must 21238451Smsmith * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step" 21338451Smsmith * and get the first record. Both macros return a NULL "enm" when there 21438451Smsmith * are no remaining records. 21538451Smsmith */ 21638451Smsmith#define ETHER_NEXT_MULTI(step, enm) \ 21738451Smsmith /* struct ether_multistep step; */ \ 21838451Smsmith /* struct ether_multi *enm; */ \ 21938451Smsmith{ \ 22038451Smsmith if (((enm) = (step).e_enm) != NULL) \ 22138451Smsmith (step).e_enm = (enm)->enm_list.le_next; \ 22238451Smsmith} 22338451Smsmith 22438451Smsmith#define ETHER_FIRST_MULTI(step, ac, enm) \ 22538451Smsmith /* struct ether_multistep step; */ \ 22638451Smsmith /* struct arpcom *ac; */ \ 22738451Smsmith /* struct ether_multi *enm; */ \ 22838451Smsmith{ \ 22938451Smsmith (step).e_enm = (ac)->ac_multiaddrs.lh_first; \ 23038451Smsmith ETHER_NEXT_MULTI((step), (enm)); \ 23138451Smsmith} 23238451Smsmith 23338451Smsmith#ifdef _KERNEL 23438451Smsmithvoid arp_rtrequest(int, struct rtentry *, struct sockaddr *); 23538451Smsmithint arpresolve(struct arpcom *, struct rtentry *, struct mbuf *, 236186119Sqingli struct sockaddr *, u_char *, struct llentry **); 23738451Smsmithvoid arpintr(void); 23838451Smsmithint arpioctl(u_long, caddr_t); 23938451Smsmithvoid arp_ifinit(struct arpcom *, struct ifaddr *); 24038451Smsmithvoid revarpinput(struct mbuf *); 24138451Smsmithvoid in_revarpinput(struct mbuf *); 24238451Smsmithvoid revarprequest(struct ifnet *); 24338451Smsmithint revarpwhoarewe(struct ifnet *, struct in_addr *, struct in_addr *); 24438451Smsmithint revarpwhoami(struct in_addr *, struct ifnet *); 24538451Smsmithint db_show_arptab(void); 24638451Smsmith#endif 24738451Smsmith 24838451Smsmith/* 24938451Smsmith * Prototype ethers(3) functions. 25038451Smsmith */ 25138451Smsmith#ifndef _KERNEL 25238451Smsmith#include <sys/cdefs.h> 25338451Smsmith__BEGIN_DECLS 25438451Smsmithchar * ether_ntoa(struct ether_addr *); 25538451Smsmithstruct ether_addr * 25638451Smsmith ether_aton(char *); 25738451Smsmithint ether_ntohost(char *, struct ether_addr *); 25838451Smsmithint ether_hostton(char *, struct ether_addr *); 25938451Smsmithint ether_line(char *, struct ether_addr *, char *); 26038451Smsmith__END_DECLS 26138451Smsmith#endif 262