ip6.h revision 6017:7e310503019e
19793Sakash.bagdia@arm.com/*
28706Sandreas.hansson@arm.com * ip6.h
38706Sandreas.hansson@arm.com *
48706Sandreas.hansson@arm.com * Internet Protocol, Version 6 (RFC 2460).
58706Sandreas.hansson@arm.com *
68706Sandreas.hansson@arm.com * Copyright (c) 2002 Dug Song <dugsong@monkey.org>
78706Sandreas.hansson@arm.com *
88706Sandreas.hansson@arm.com * $Id: ip6.h,v 1.6 2004/02/23 10:01:15 dugsong Exp $
98706Sandreas.hansson@arm.com */
108706Sandreas.hansson@arm.com
118706Sandreas.hansson@arm.com#ifndef DNET_IP6_H
128706Sandreas.hansson@arm.com#define DNET_IP6_H
135369Ssaidi@eecs.umich.edu
143005Sstever@eecs.umich.edu#define IP6_ADDR_LEN	16
153005Sstever@eecs.umich.edu#define IP6_ADDR_BITS	128
163005Sstever@eecs.umich.edu
173005Sstever@eecs.umich.edu#define IP6_HDR_LEN	40		/* IPv6 header length */
183005Sstever@eecs.umich.edu#define IP6_LEN_MIN	IP6_HDR_LEN
193005Sstever@eecs.umich.edu#define IP6_LEN_MAX	65535		/* non-jumbo payload */
203005Sstever@eecs.umich.edu
213005Sstever@eecs.umich.edu#define IP6_MTU_MIN	1280		/* minimum MTU (1024 + 256) */
223005Sstever@eecs.umich.edu
233005Sstever@eecs.umich.edutypedef struct ip6_addr {
243005Sstever@eecs.umich.edu        uint8_t         data[IP6_ADDR_LEN];
253005Sstever@eecs.umich.edu} ip6_addr_t;
263005Sstever@eecs.umich.edu
273005Sstever@eecs.umich.edu#ifndef __GNUC__
283005Sstever@eecs.umich.edu# define __attribute__(x)
293005Sstever@eecs.umich.edu# pragma pack(1)
303005Sstever@eecs.umich.edu#endif
313005Sstever@eecs.umich.edu
323005Sstever@eecs.umich.edu/*
333005Sstever@eecs.umich.edu * IPv6 header
343005Sstever@eecs.umich.edu */
353005Sstever@eecs.umich.edustruct ip6_hdr {
363005Sstever@eecs.umich.edu        union {
373005Sstever@eecs.umich.edu                struct ip6_hdr_ctl {
383005Sstever@eecs.umich.edu                        uint32_t	ip6_un1_flow; /* 20 bits of flow ID */
393005Sstever@eecs.umich.edu                        uint16_t	ip6_un1_plen; /* payload length */
403005Sstever@eecs.umich.edu                        uint8_t		ip6_un1_nxt;  /* next header */
412710SN/A                        uint8_t		ip6_un1_hlim; /* hop limit */
422710SN/A                } ip6_un1;
433005Sstever@eecs.umich.edu                uint8_t	ip6_un2_vfc;	/* 4 bits version, top 4 bits class */
442889SN/A        } ip6_ctlun;
456654Snate@binkert.org        ip6_addr_t	ip6_src;
466654Snate@binkert.org        ip6_addr_t	ip6_dst;
476654Snate@binkert.org} __attribute__((__packed__));
482667SN/A
496654Snate@binkert.org#define ip6_vfc		ip6_ctlun.ip6_un2_vfc
506654Snate@binkert.org#define ip6_flow	ip6_ctlun.ip6_un1.ip6_un1_flow
516654Snate@binkert.org#define ip6_plen	ip6_ctlun.ip6_un1.ip6_un1_plen
525457Ssaidi@eecs.umich.edu#define ip6_nxt		ip6_ctlun.ip6_un1.ip6_un1_nxt	/* IP_PROTO_* */
536654Snate@binkert.org#define ip6_hlim	ip6_ctlun.ip6_un1.ip6_un1_hlim
548169SLisa.Hsu@amd.com
559100SBrad.Beckmann@amd.com#define IP6_VERSION		0x60
568169SLisa.Hsu@amd.com#define IP6_VERSION_MASK	0xf0		/* ip6_vfc version */
578920Snilay@cs.wisc.edu
588169SLisa.Hsu@amd.com#if DNET_BYTESEX == DNET_BIG_ENDIAN
593395Shsul@eecs.umich.edu#define IP6_FLOWINFO_MASK	0x0fffffff	/* ip6_flow info (28 bits) */
606981SLisa.Hsu@amd.com#define IP6_FLOWLABEL_MASK	0x000fffff	/* ip6_flow label (20 bits) */
613448Shsul@eecs.umich.edu#elif DNET_BYTESEX == DNET_LIL_ENDIAN
625369Ssaidi@eecs.umich.edu#define IP6_FLOWINFO_MASK	0xffffff0f	/* ip6_flow info (28 bits) */
633394Shsul@eecs.umich.edu#define IP6_FLOWLABEL_MASK	0xffff0f00	/* ip6_flow label (20 bits) */
649197Snilay@cs.wisc.edu#endif
659197Snilay@cs.wisc.edu
669197Snilay@cs.wisc.edu/*
679197Snilay@cs.wisc.edu * Hop limit (ip6_hlim)
689197Snilay@cs.wisc.edu */
699197Snilay@cs.wisc.edu#define IP6_HLIM_DEFAULT	64
709197Snilay@cs.wisc.edu#define IP6_HLIM_MAX		255
719197Snilay@cs.wisc.edu
729197Snilay@cs.wisc.edu/*
739197Snilay@cs.wisc.edu * Preferred extension header order from RFC 2460, 4.1:
749197Snilay@cs.wisc.edu *
759197Snilay@cs.wisc.edu * IP_PROTO_IPV6, IP_PROTO_HOPOPTS, IP_PROTO_DSTOPTS, IP_PROTO_ROUTING,
769197Snilay@cs.wisc.edu * IP_PROTO_FRAGMENT, IP_PROTO_AH, IP_PROTO_ESP, IP_PROTO_DSTOPTS, IP_PROTO_*
779197Snilay@cs.wisc.edu */
789197Snilay@cs.wisc.edu
799197Snilay@cs.wisc.edu/*
809197Snilay@cs.wisc.edu * Routing header data (IP_PROTO_ROUTING)
819197Snilay@cs.wisc.edu */
829197Snilay@cs.wisc.edustruct ip6_ext_data_routing {
839197Snilay@cs.wisc.edu        uint8_t  type;			/* routing type */
849197Snilay@cs.wisc.edu        uint8_t  segleft;		/* segments left */
859197Snilay@cs.wisc.edu        /* followed by routing type specific data */
869197Snilay@cs.wisc.edu} __attribute__((__packed__));
879197Snilay@cs.wisc.edu
889197Snilay@cs.wisc.edustruct ip6_ext_data_routing0 {
899217Snilay@cs.wisc.edu        uint8_t  type;			/* always zero */
909197Snilay@cs.wisc.edu        uint8_t  segleft;		/* segments left */
919197Snilay@cs.wisc.edu        uint8_t  reserved;		/* reserved field */
929197Snilay@cs.wisc.edu        uint8_t  slmap[3];		/* strict/loose bit map */
939197Snilay@cs.wisc.edu        ip6_addr_t  addr[1];		/* up to 23 addresses */
949197Snilay@cs.wisc.edu} __attribute__((__packed__));
959197Snilay@cs.wisc.edu
969197Snilay@cs.wisc.edu/*
979197Snilay@cs.wisc.edu * Fragment header data (IP_PROTO_FRAGMENT)
989197Snilay@cs.wisc.edu */
999197Snilay@cs.wisc.edustruct ip6_ext_data_fragment {
1009197Snilay@cs.wisc.edu        uint16_t  offlg;		/* offset, reserved, and flag */
1019197Snilay@cs.wisc.edu        uint32_t  ident;		/* identification */
1029197Snilay@cs.wisc.edu} __attribute__((__packed__));
1039197Snilay@cs.wisc.edu
1049197Snilay@cs.wisc.edu/*
1059197Snilay@cs.wisc.edu * Fragmentation offset, reserved, and flags (offlg)
1069197Snilay@cs.wisc.edu */
1079197Snilay@cs.wisc.edu#if DNET_BYTESEX == DNET_BIG_ENDIAN
1089197Snilay@cs.wisc.edu#define IP6_OFF_MASK		0xfff8	/* mask out offset from offlg */
1099197Snilay@cs.wisc.edu#define IP6_RESERVED_MASK	0x0006	/* reserved bits in offlg */
1102957SN/A#define IP6_MORE_FRAG		0x0001	/* more-fragments flag */
1118920Snilay@cs.wisc.edu#elif DNET_BYTESEX == DNET_LIL_ENDIAN
1128920Snilay@cs.wisc.edu#define IP6_OFF_MASK		0xf8ff	/* mask out offset from offlg */
1132957SN/A#define IP6_RESERVED_MASK	0x0600	/* reserved bits in offlg */
1148862Snilay@cs.wisc.edu#define IP6_MORE_FRAG		0x0100	/* more-fragments flag */
1158862Snilay@cs.wisc.edu#endif
1168467Snilay@cs.wisc.edu
1172957SN/A/*
1182957SN/A * Option types, for IP_PROTO_HOPOPTS, IP_PROTO_DSTOPTS headers
1192957SN/A */
1202957SN/A#define IP6_OPT_PAD1		0x00	/* 00 0 00000 */
1212957SN/A#define IP6_OPT_PADN		0x01	/* 00 0 00001 */
1222957SN/A#define IP6_OPT_JUMBO		0xC2	/* 11 0 00010 = 194 */
1238167SLisa.Hsu@amd.com#define IP6_OPT_JUMBO_LEN	6
1249197Snilay@cs.wisc.edu#define IP6_OPT_RTALERT		0x05	/* 00 0 00101 */
1258167SLisa.Hsu@amd.com#define IP6_OPT_RTALERT_LEN	4
1265369Ssaidi@eecs.umich.edu#define IP6_OPT_RTALERT_MLD	0	/* Datagram contains an MLD message */
1278167SLisa.Hsu@amd.com#define IP6_OPT_RTALERT_RSVP	1	/* Datagram contains an RSVP message */
1288167SLisa.Hsu@amd.com#define IP6_OPT_RTALERT_ACTNET	2 	/* contains an Active Networks msg */
1298167SLisa.Hsu@amd.com#define IP6_OPT_LEN_MIN		2
1308167SLisa.Hsu@amd.com
1318167SLisa.Hsu@amd.com#define IP6_OPT_TYPE(o)		((o) & 0xC0)	/* high 2 bits of opt_type */
1328167SLisa.Hsu@amd.com#define IP6_OPT_TYPE_SKIP	0x00	/* continue processing on failure */
1338167SLisa.Hsu@amd.com#define IP6_OPT_TYPE_DISCARD	0x40	/* discard packet on failure */
1348168SLisa.Hsu@amd.com#define IP6_OPT_TYPE_FORCEICMP	0x80	/* discard and send ICMP on failure */
1358168SLisa.Hsu@amd.com#define IP6_OPT_TYPE_ICMP	0xC0	/* ...only if non-multicast dst */
1368168SLisa.Hsu@amd.com
1378168SLisa.Hsu@amd.com#define IP6_OPT_MUTABLE		0x20	/* option data may change en route */
1388167SLisa.Hsu@amd.com
1398167SLisa.Hsu@amd.com/*
1408168SLisa.Hsu@amd.com * Extension header (chained via {ip6,ext}_nxt, following IPv6 header)
1415369Ssaidi@eecs.umich.edu */
1428920Snilay@cs.wisc.edustruct ip6_ext_hdr {
1439197Snilay@cs.wisc.edu        uint8_t  ext_nxt;	/* next header */
1448920Snilay@cs.wisc.edu        uint8_t  ext_len;	/* following length in units of 8 octets */
1458920Snilay@cs.wisc.edu        union {
1468920Snilay@cs.wisc.edu                struct ip6_ext_data_routing	routing;
1475369Ssaidi@eecs.umich.edu                struct ip6_ext_data_fragment	fragment;
1485369Ssaidi@eecs.umich.edu        } ext_data;
1498718Snilay@cs.wisc.edu} __attribute__((__packed__));
1509197Snilay@cs.wisc.edu
1519197Snilay@cs.wisc.edu#ifndef __GNUC__
1529665Sandreas.hansson@arm.com# pragma pack()
1539665Sandreas.hansson@arm.com#endif
1549197Snilay@cs.wisc.edu
1559197Snilay@cs.wisc.edu/*
1569197Snilay@cs.wisc.edu * Reserved addresses
1573005Sstever@eecs.umich.edu */
1583395Shsul@eecs.umich.edu#define IP6_ADDR_UNSPEC	\
1593395Shsul@eecs.umich.edu        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
1609800Snilay@cs.wisc.edu#define IP6_ADDR_LOOPBACK \
1619793Sakash.bagdia@arm.com        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
1629815SAndreas Hansson <andreas.hansson>
1639793Sakash.bagdia@arm.com#define ip6_pack_hdr(hdr, fc, fl, plen, nxt, hlim, src, dst) do {	\
1649827Sakash.bagdia@arm.com        struct ip6_hdr *ip6 = (struct ip6_hdr *)(hdr);			\
1659827Sakash.bagdia@arm.com        ip6->ip6_flow = htonl(((uint32_t)(fc) << 28) &			\
1669827Sakash.bagdia@arm.com            (IP6_FLOWLABEL_MASK | (fl)));				\
1679827Sakash.bagdia@arm.com        ip6->ip6_vfc = (IP6_VERSION | ((fc) >> 4));			\
1689827Sakash.bagdia@arm.com        ip6->ip6_plen = htons((plen));					\
1699827Sakash.bagdia@arm.com        ip6->ip6_nxt = (nxt); ip6->ip6_hlim = (hlim);			\
1709827Sakash.bagdia@arm.com        memmove(&ip6->ip6_src, &(src), IP6_ADDR_LEN);			\
1719827Sakash.bagdia@arm.com        memmove(&ip6->ip6_dst, &(dst), IP6_ADDR_LEN);			\
1729827Sakash.bagdia@arm.com} while (0);
1739827Sakash.bagdia@arm.com
1749793Sakash.bagdia@arm.com__BEGIN_DECLS
1759827Sakash.bagdia@arm.comchar	*ip6_ntop(const ip6_addr_t *ip6, char *dst, size_t size);
1769827Sakash.bagdia@arm.comint	 ip6_pton(const char *src, ip6_addr_t *dst);
1779827Sakash.bagdia@arm.comchar	*ip6_ntoa(const ip6_addr_t *ip6);
1789793Sakash.bagdia@arm.com#define	 ip6_aton ip6_pton
1799793Sakash.bagdia@arm.com
1809793Sakash.bagdia@arm.comvoid	 ip6_checksum(void *buf, size_t len);
1819793Sakash.bagdia@arm.com__END_DECLS
1829793Sakash.bagdia@arm.com
1833395Shsul@eecs.umich.edu#endif /* DNET_IP6_H */
1848926Sandreas.hansson@arm.com