The first version that was demonstrated to get an IPv6 address
[firmerware] / include / 0cpm / netinet.h
1 /* netinet.h -- network data structures
2  *
3  * This file is part of 0cpm Firmerware.
4  *
5  * 0cpm Firmerware is Copyright (c)2011 Rick van Rein, OpenFortress.
6  *
7  * 0cpm Firmerware is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation, version 3.
10  *
11  * 0cpm Firmerware is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with 0cpm Firmerware.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 /* 0cpm firmerware
22  *
23  * Much of what follows was taken from Linux, but trimmed down to
24  * convey only uint8_t[] arrays to represent network packets.  The
25  * need for this arises from some DSP processors like tic55x, that
26  * work under an unconventional
27  *      sizeof (uint8_t) == sizeof (uint16_t) == 2
28  * because their memory is 16-bit and can be used as 8-bit-only.
29  *
30  * The only way to generically overlay packets with structs is to
31  * define all parts of those structs in terms of uint8_t[] and
32  * use generic routines netget16() / netput16() and so on to change
33  * the values stored in these fields.  Of course, optimisations are
34  * possible for concrete local architectures; this is why the defs
35  * of netget16, netput16 and so on are only done if the symbols have
36  * not been defined in the bottom-half specific include files.
37  */
38
39
40 #ifndef HEADER_NETINET
41 #define HEADER_NETINET
42
43
44 /* The network-specific definitions of 8, 16 and 32 bit values that
45  * are generic enough to work on special DSP processors as well,
46  * together with their utility functions.  Use the netget16, netput16
47  * and so on instead of manipulating values with htons, ntohs and so on.
48  */
49
50 typedef struct { uint8_t b0             } nint8_t;
51 typedef struct { uint8_t b0, b1         } nint16_t;
52 typedef struct { uint8_t b0, b1, b2, b3 } nint32_t;
53
54 #ifndef netget8
55 #define netget8(a) ((uint8_t) (a).b0)
56 #endif
57
58 #ifndef netget16
59 #define netget16(a) ((((uint16_t) (a).b0) << 8) | ((uint16_t) ((a).b1)))
60 #endif
61
62 #ifndef netget32
63 #define netget32(a) ((((uint32_t) (a).b0) << 24) | (((uint32_t) (a).b1) << 16) | (((uint32_t) (a).b2) << 8) | (((uint32_t) (a).b3)))
64 #endif
65
66 #ifndef netset8
67 #define netset8(a,v) (((a).b0) = (v))
68 #endif
69
70 #ifndef netset16
71 #define netset16(a,v) (((a).b0 = ((v) >> 8)), ((a).b1 = ((v) & 0xff)), (v))
72 #endif
73
74 #ifndef netset32
75 #define netset32(a,v) (((a).b0 = ((v) >> 24)), ((a).b1 = (((v) >> 16) & 0xff)), ((a).b2 = (((v) >> 8) & 0xff)), ((a).b3 = ((v) & 0xff)), (v))
76 #endif
77
78 /* Note: In bottom-specific overrides, raise an error if these values
79  * are defined before they are redefined for that specific bottom.
80  * This will raise awareness of the order of header files, and avoid
81  * different definitions (albeit semantically compatible) in various
82  * files due to varying include orders.  The right order is always
83  * to include the bottom-half include files before the top half files.
84  */
85
86
87 /* Start includes, mostly taken from Linux header files */
88
89
90 /* Standard well-defined IP protocols.  */
91 enum {
92   IPPROTO_IP = 0,               /* Dummy protocol for TCP               */
93   IPPROTO_ICMP = 1,             /* Internet Control Message Protocol    */
94   IPPROTO_IGMP = 2,             /* Internet Group Management Protocol   */
95   IPPROTO_IPIP = 4,             /* IPIP tunnels (older KA9Q tunnels use 94) */
96   IPPROTO_TCP = 6,              /* Transmission Control Protocol        */
97   IPPROTO_EGP = 8,              /* Exterior Gateway Protocol            */
98   IPPROTO_PUP = 12,             /* PUP protocol                         */
99   IPPROTO_UDP = 17,             /* User Datagram Protocol               */
100   IPPROTO_IDP = 22,             /* XNS IDP protocol                     */
101   IPPROTO_DCCP = 33,            /* Datagram Congestion Control Protocol */
102   IPPROTO_RSVP = 46,            /* RSVP protocol                        */
103   IPPROTO_GRE = 47,             /* Cisco GRE tunnels (rfc 1701,1702)    */
104
105   IPPROTO_IPV6   = 41,          /* IPv6-in-IPv4 tunnelling              */
106
107   IPPROTO_ESP = 50,            /* Encapsulation Security Payload protocol */
108   IPPROTO_AH = 51,             /* Authentication Header protocol       */
109   IPPROTO_BEETPH = 94,         /* IP option pseudo header for BEET */
110   IPPROTO_PIM    = 103,         /* Protocol Independent Multicast       */
111
112   IPPROTO_COMP   = 108,                /* Compression Header protocol */
113   IPPROTO_SCTP   = 132,         /* Stream Control Transport Protocol    */
114   IPPROTO_UDPLITE = 136,        /* UDP-Lite (RFC 3828)                  */
115
116   IPPROTO_RAW    = 255,         /* Raw IP packets                       */
117   IPPROTO_MAX
118 };
119
120 /*
121  *      IPV6 extension headers
122  */
123 #define IPPROTO_HOPOPTS         0       /* IPv6 hop-by-hop options      */
124 #define IPPROTO_ROUTING         43      /* IPv6 routing header          */
125 #define IPPROTO_FRAGMENT        44      /* IPv6 fragmentation header    */
126 #define IPPROTO_ICMPV6          58      /* ICMPv6                       */
127 #define IPPROTO_NONE            59      /* IPv6 no next header          */
128 #define IPPROTO_DSTOPTS         60      /* IPv6 destination options     */
129 #define IPPROTO_MH              135     /* IPv6 mobility header         */
130
131 /*
132  *      IEEE 802.3 Ethernet magic constants.  The frame sizes omit the preamble
133  *      and FCS/CRC (frame check sequence). 
134  */
135
136 #define ETH_ALEN        6               /* Octets in one ethernet addr   */
137 #define ETH_HLEN        14              /* Total octets in header.       */
138 #define ETH_ZLEN        60              /* Min. octets in frame sans FCS */
139 #define ETH_DATA_LEN    1500            /* Max. octets in payload        */
140 #define ETH_FRAME_LEN   1514            /* Max. octets in frame sans FCS */
141 #define ETH_FCS_LEN     4               /* Octets in the FCS             */
142
143 /* Ethernet protocol ID's */
144 #define ETHERTYPE_PUP           0x0200          /* Xerox PUP */
145 #define ETHERTYPE_SPRITE        0x0500          /* Sprite */
146 #define ETHERTYPE_IP            0x0800          /* IP */
147 #define ETHERTYPE_ARP           0x0806          /* Address resolution */
148 #define ETHERTYPE_REVARP        0x8035          /* Reverse ARP */
149 #define ETHERTYPE_AT            0x809B          /* AppleTalk protocol */
150 #define ETHERTYPE_AARP          0x80F3          /* AppleTalk ARP */
151 #define ETHERTYPE_VLAN          0x8100          /* IEEE 802.1Q VLAN tagging */
152 #define ETHERTYPE_IPX           0x8137          /* IPX */
153 #define ETHERTYPE_IPV6          0x86dd          /* IP protocol version 6 */
154 #define ETHERTYPE_LOOPBACK      0x9000          /* used to test interfaces */
155
156
157 #define ETHER_ADDR_LEN  ETH_ALEN                 /* size of ethernet addr */
158 #define ETHER_TYPE_LEN  2                        /* bytes in type field */
159 #define ETHER_CRC_LEN   4                        /* bytes in CRC field */
160 #define ETHER_HDR_LEN   ETH_HLEN                 /* total octets in header */
161 #define ETHER_MIN_LEN   (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
162 #define ETHER_MAX_LEN   (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
163
164
165 /*
166  *      These are the defined Ethernet Protocol ID's.
167  */
168
169 #define ETH_P_LOOP      0x0060          /* Ethernet Loopback packet     */
170 #define ETH_P_PUP       0x0200          /* Xerox PUP packet             */
171 #define ETH_P_PUPAT     0x0201          /* Xerox PUP Addr Trans packet  */
172 #define ETH_P_IP        0x0800          /* Internet Protocol packet     */
173 #define ETH_P_X25       0x0805          /* CCITT X.25                   */
174 #define ETH_P_ARP       0x0806          /* Address Resolution packet    */
175 #define ETH_P_BPQ       0x08FF          /* G8BPQ AX.25 Ethernet Packet  [ NOT AN OFFICIALLY REGISTERED ID ] */
176 #define ETH_P_IEEEPUP   0x0a00          /* Xerox IEEE802.3 PUP packet */
177 #define ETH_P_IEEEPUPAT 0x0a01          /* Xerox IEEE802.3 PUP Addr Trans packet */
178 #define ETH_P_DEC       0x6000          /* DEC Assigned proto           */
179 #define ETH_P_DNA_DL    0x6001          /* DEC DNA Dump/Load            */
180 #define ETH_P_DNA_RC    0x6002          /* DEC DNA Remote Console       */
181 #define ETH_P_DNA_RT    0x6003          /* DEC DNA Routing              */
182 #define ETH_P_LAT       0x6004          /* DEC LAT                      */
183 #define ETH_P_DIAG      0x6005          /* DEC Diagnostics              */
184 #define ETH_P_CUST      0x6006          /* DEC Customer use             */
185 #define ETH_P_SCA       0x6007          /* DEC Systems Comms Arch       */
186 #define ETH_P_RARP      0x8035          /* Reverse Addr Res packet      */
187 #define ETH_P_ATALK     0x809B          /* Appletalk DDP                */
188 #define ETH_P_AARP      0x80F3          /* Appletalk AARP               */
189 #define ETH_P_8021Q     0x8100          /* 802.1Q VLAN Extended Header  */
190 #define ETH_P_IPX       0x8137          /* IPX over DIX                 */
191 #define ETH_P_IPV6      0x86DD          /* IPv6 over bluebook           */
192 #define ETH_P_PAUSE     0x8808          /* IEEE Pause frames. See 802.3 31B */
193 #define ETH_P_SLOW      0x8809          /* Slow Protocol. See 802.3ad 43B */
194 #define ETH_P_WCCP      0x883E          /* Web-cache coordination protocol
195                                          * defined in draft-wilson-wrec-wccp-v2-00.txt */
196 #define ETH_P_PPP_DISC  0x8863          /* PPPoE discovery messages     */
197 #define ETH_P_PPP_SES   0x8864          /* PPPoE session messages       */
198 #define ETH_P_MPLS_UC   0x8847          /* MPLS Unicast traffic         */
199 #define ETH_P_MPLS_MC   0x8848          /* MPLS Multicast traffic       */
200 #define ETH_P_ATMMPOA   0x884c          /* MultiProtocol Over ATM       */
201 #define ETH_P_ATMFATE   0x8884          /* Frame-based ATM Transport
202                                          * over Ethernet
203                                          */
204 #define ETH_P_AOE       0x88A2          /* ATA over Ethernet            */
205 #define ETH_P_TIPC      0x88CA          /* TIPC                         */
206
207 /* Internet address.  */
208 typedef nint32_t in_addr_t;
209 struct in_addr
210   {
211     in_addr_t s_addr;
212   };
213
214
215 /*
216  * Structure of an internet header, naked of options.
217  */
218 struct ip
219   {
220 // #if __BYTE_ORDER == __LITTLE_ENDIAN
221     // unsigned int ip_hl:4;               /* header length */
222     // unsigned int ip_v:4;                /* version */
223 // #endif
224 // #if __BYTE_ORDER == __BIG_ENDIAN
225     unsigned int ip_v:4;                /* version */
226     unsigned int ip_hl:4;               /* header length */
227 // #endif
228     nint8_t ip_tos;                    /* type of service */
229     nint16_t ip_len;                     /* total length */
230     nint16_t ip_id;                      /* identification */
231     nint16_t ip_off;                     /* fragment offset field */
232 #define IP_RF 0x8000                    /* reserved fragment flag */
233 #define IP_DF 0x4000                    /* dont fragment flag */
234 #define IP_MF 0x2000                    /* more fragments flag */
235 #define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
236     nint8_t ip_ttl;                    /* time to live */
237     nint8_t ip_p;                      /* protocol */
238     nint16_t ip_sum;                     /* checksum */
239     struct in_addr ip_src, ip_dst;      /* source and dest address */
240   };
241
242
243 struct iphdr
244   {
245     nint8_t version_ihl;
246     nint8_t tos;
247     nint16_t tot_len;
248     nint16_t id;
249     nint16_t frag_off;
250     nint8_t ttl;
251     nint8_t protocol;
252     nint16_t check;
253     nint32_t saddr;
254     nint32_t daddr;
255     /*The options start here. */
256   };
257
258
259
260 struct icmp6_hdr
261   {
262     nint8_t     icmp6_type;   /* type field */
263     nint8_t     icmp6_code;   /* code field */
264     nint16_t    icmp6_cksum;  /* checksum field */
265     union
266       {
267         nint32_t  icmp6_un_data32[1]; /* type-specific field */
268         nint16_t  icmp6_un_data16[2]; /* type-specific field */
269         nint8_t   icmp6_un_data8[4];  /* type-specific field */
270       } icmp6_dataun;
271   };
272
273 #define icmp6_data32    icmp6_dataun.icmp6_un_data32
274 #define icmp6_data16    icmp6_dataun.icmp6_un_data16
275 #define icmp6_data8     icmp6_dataun.icmp6_un_data8
276 #define icmp6_pptr      icmp6_data32[0]  /* parameter prob */
277 #define icmp6_mtu       icmp6_data32[0]  /* packet too big */
278 #define icmp6_id        icmp6_data16[0]  /* echo request/reply */
279 #define icmp6_seq       icmp6_data16[1]  /* echo request/reply */
280 #define icmp6_maxdelay  icmp6_data16[0]  /* mcast group membership */
281
282
283 #define ICMP6_DST_UNREACH             1
284 #define ICMP6_PACKET_TOO_BIG          2
285 #define ICMP6_TIME_EXCEEDED           3
286 #define ICMP6_PARAM_PROB              4
287
288 #define ICMP6_INFOMSG_MASK  0x80    /* all informational messages */
289
290 #define ICMP6_ECHO_REQUEST          128
291 #define ICMP6_ECHO_REPLY            129
292 #define MLD_LISTENER_QUERY          130
293 #define MLD_LISTENER_REPORT         131
294 #define MLD_LISTENER_REDUCTION      132
295
296 #define ICMP6_DST_UNREACH_NOROUTE     0 /* no route to destination */
297 #define ICMP6_DST_UNREACH_ADMIN       1 /* communication with destination */
298                                         /* administratively prohibited */
299 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
300 #define ICMP6_DST_UNREACH_ADDR        3 /* address unreachable */
301 #define ICMP6_DST_UNREACH_NOPORT      4 /* bad port */
302
303 #define ICMP6_TIME_EXCEED_TRANSIT     0 /* Hop Limit == 0 in transit */
304 #define ICMP6_TIME_EXCEED_REASSEMBLY  1 /* Reassembly time out */
305
306 #define ICMP6_PARAMPROB_HEADER        0 /* erroneous header field */
307 #define ICMP6_PARAMPROB_NEXTHEADER    1 /* unrecognized Next Header */
308 #define ICMP6_PARAMPROB_OPTION        2 /* unrecognized IPv6 option */
309
310
311 #define ND_ROUTER_SOLICIT           133
312 #define ND_ROUTER_ADVERT            134
313 #define ND_NEIGHBOR_SOLICIT         135
314 #define ND_NEIGHBOR_ADVERT          136
315 #define ND_REDIRECT                 137
316
317 #define ND_OPT_SOURCE_LINKADDR          1
318 #define ND_OPT_TARGET_LINKADDR          2
319 #define ND_OPT_PREFIX_INFORMATION       3
320 #define ND_OPT_REDIRECTED_HEADER        4
321 #define ND_OPT_MTU                      5
322 #define ND_OPT_RTR_ADV_INTERVAL         7
323 #define ND_OPT_HOME_AGENT_INFO          8
324
325 #define ND_OPT_PI_FLAG_ONLINK   0x80
326 #define ND_OPT_PI_FLAG_AUTO     0x40
327 #define ND_OPT_PI_FLAG_RADDR    0x20
328
329
330
331 /*
332  * Internal of an ICMP Router Advertisement
333  */
334 struct icmp_ra_addr
335 {
336   nint32_t ira_addr;
337   nint32_t ira_preference;
338 };
339
340
341 struct icmp
342 {
343   nint8_t  icmp_type;  /* type of message, see below */
344   nint8_t  icmp_code;  /* type sub code */
345   nint16_t icmp_cksum; /* ones complement checksum of struct */
346   union
347   {
348     nint8_t ih_pptr;             /* ICMP_PARAMPROB */
349     struct in_addr ih_gwaddr;   /* gateway address */
350     struct ih_idseq             /* echo datagram */
351     {
352       nint16_t icd_id;
353       nint16_t icd_seq;
354     } ih_idseq;
355     nint32_t ih_void;
356
357     /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
358     struct ih_pmtu
359     {
360       nint16_t ipm_void;
361       nint16_t ipm_nextmtu;
362     } ih_pmtu;
363
364     struct ih_rtradv
365     {
366       nint8_t irt_num_addrs;
367       nint8_t irt_wpa;
368       nint16_t irt_lifetime;
369     } ih_rtradv;
370   } icmp_hun;
371 #define icmp_pptr       icmp_hun.ih_pptr
372 #define icmp_gwaddr     icmp_hun.ih_gwaddr
373 #define icmp_id         icmp_hun.ih_idseq.icd_id
374 #define icmp_seq        icmp_hun.ih_idseq.icd_seq
375 #define icmp_void       icmp_hun.ih_void
376 #define icmp_pmvoid     icmp_hun.ih_pmtu.ipm_void
377 #define icmp_nextmtu    icmp_hun.ih_pmtu.ipm_nextmtu
378 #define icmp_num_addrs  icmp_hun.ih_rtradv.irt_num_addrs
379 #define icmp_wpa        icmp_hun.ih_rtradv.irt_wpa
380 #define icmp_lifetime   icmp_hun.ih_rtradv.irt_lifetime
381   union
382   {
383     struct
384     {
385       nint32_t its_otime;
386       nint32_t its_rtime;
387       nint32_t its_ttime;
388     } id_ts;
389     struct
390     {
391       struct ip idi_ip;
392       /* options and then 64 bits of data */
393     } id_ip;
394     struct icmp_ra_addr id_radv;
395     nint32_t   id_mask;
396     nint8_t    id_data[1];
397   } icmp_dun;
398 #define icmp_otime      icmp_dun.id_ts.its_otime
399 #define icmp_rtime      icmp_dun.id_ts.its_rtime
400 #define icmp_ttime      icmp_dun.id_ts.its_ttime
401 #define icmp_ip         icmp_dun.id_ip.idi_ip
402 #define icmp_radv       icmp_dun.id_radv
403 #define icmp_mask       icmp_dun.id_mask
404 #define icmp_data       icmp_dun.id_data
405 };
406
407
408 struct icmphdr
409 {
410   nint8_t type;                /* message type */
411   nint8_t code;                /* type sub-code */
412   nint16_t checksum;
413   union
414   {
415     struct
416     {
417       nint16_t id;
418       nint16_t sequence;
419     } echo;                     /* echo datagram */
420     nint32_t   gateway;        /* gateway address */
421     struct
422     {
423       nint16_t __unused;
424       nint16_t mtu;
425     } frag;                     /* path mtu discovery */
426   } un;
427 };
428
429
430 #define ICMP_ECHOREPLY          0       /* Echo Reply                   */
431 #define ICMP_DEST_UNREACH       3       /* Destination Unreachable      */
432 #define ICMP_SOURCE_QUENCH      4       /* Source Quench                */
433 #define ICMP_REDIRECT           5       /* Redirect (change route)      */
434 #define ICMP_ECHO               8       /* Echo Request                 */
435 #define ICMP_TIME_EXCEEDED      11      /* Time Exceeded                */
436 #define ICMP_PARAMETERPROB      12      /* Parameter Problem            */
437 #define ICMP_TIMESTAMP          13      /* Timestamp Request            */
438 #define ICMP_TIMESTAMPREPLY     14      /* Timestamp Reply              */
439 #define ICMP_INFO_REQUEST       15      /* Information Request          */
440 #define ICMP_INFO_REPLY         16      /* Information Reply            */
441 #define ICMP_ADDRESS            17      /* Address Mask Request         */
442 #define ICMP_ADDRESSREPLY       18      /* Address Mask Reply           */
443 #define NR_ICMP_TYPES           18
444
445
446 /* Codes for UNREACH. */
447 #define ICMP_NET_UNREACH        0       /* Network Unreachable          */
448 #define ICMP_HOST_UNREACH       1       /* Host Unreachable             */
449 #define ICMP_PROT_UNREACH       2       /* Protocol Unreachable         */
450 #define ICMP_PORT_UNREACH       3       /* Port Unreachable             */
451 #define ICMP_FRAG_NEEDED        4       /* Fragmentation Needed/DF set  */
452 #define ICMP_SR_FAILED          5       /* Source Route failed          */
453 #define ICMP_NET_UNKNOWN        6
454 #define ICMP_HOST_UNKNOWN       7
455 #define ICMP_HOST_ISOLATED      8
456 #define ICMP_NET_ANO            9
457 #define ICMP_HOST_ANO           10
458 #define ICMP_NET_UNR_TOS        11
459 #define ICMP_HOST_UNR_TOS       12
460 #define ICMP_PKT_FILTERED       13      /* Packet filtered */
461 #define ICMP_PREC_VIOLATION     14      /* Precedence violation */
462 #define ICMP_PREC_CUTOFF        15      /* Precedence cut off */
463 #define NR_ICMP_UNREACH         15      /* instead of hardcoding immediate value */
464
465 /* Codes for REDIRECT. */
466 #define ICMP_REDIR_NET          0       /* Redirect Net                 */
467 #define ICMP_REDIR_HOST         1       /* Redirect Host                */
468 #define ICMP_REDIR_NETTOS       2       /* Redirect Net for TOS         */
469 #define ICMP_REDIR_HOSTTOS      3       /* Redirect Host for TOS        */
470
471 /* Codes for TIME_EXCEEDED. */
472 #define ICMP_EXC_TTL            0       /* TTL count exceeded           */
473 #define ICMP_EXC_FRAGTIME       1       /* Fragment Reass time exceeded */
474
475
476
477 struct udphdr
478 {
479   nint16_t source;
480   nint16_t dest;
481   nint16_t len;
482   nint16_t check;
483 };
484
485
486 /* IPv6 address */
487 struct in6_addr
488   {
489     union
490       {
491         nint8_t u6_addr8[16];
492         nint16_t u6_addr16[8];
493         nint32_t u6_addr32[4];
494       } in6_u;
495 #define s6_addr                 in6_u.u6_addr8
496 #define s6_addr16               in6_u.u6_addr16
497 #define s6_addr32               in6_u.u6_addr32
498   };
499
500 #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
501 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
502
503 #define INET_ADDRSTRLEN 16
504 #define INET6_ADDRSTRLEN 46
505
506
507 struct ip6_hdr
508   {
509     union
510       {
511         struct ip6_hdrctl
512           {
513             nint32_t ip6_un1_flow;   /* 4 bits version, 8 bits TC,
514                                         20 bits flow-ID */
515             nint16_t ip6_un1_plen;   /* payload length */
516             nint8_t  ip6_un1_nxt;    /* next header */
517             nint8_t  ip6_un1_hlim;   /* hop limit */
518           } ip6_un1;
519         nint8_t ip6_un2_vfc;       /* 4 bits version, top 4 bits tclass */
520       } ip6_ctlun;
521     struct in6_addr ip6_src;      /* source address */
522     struct in6_addr ip6_dst;      /* destination address */
523   };
524
525 #define ip6_vfc   ip6_ctlun.ip6_un2_vfc
526 #define ip6_flow  ip6_ctlun.ip6_un1.ip6_un1_flow
527 #define ip6_plen  ip6_ctlun.ip6_un1.ip6_un1_plen
528 #define ip6_nxt   ip6_ctlun.ip6_un1.ip6_un1_nxt
529 #define ip6_hlim  ip6_ctlun.ip6_un1.ip6_un1_hlim
530 #define ip6_hops  ip6_ctlun.ip6_un1.ip6_un1_hlim
531
532 /* This structure defines an ethernet arp header.  */
533
534 /* ARP protocol opcodes. */
535 #define ARPOP_REQUEST   1               /* ARP request.  */
536 #define ARPOP_REPLY     2               /* ARP reply.  */
537 #define ARPOP_RREQUEST  3               /* RARP request.  */
538 #define ARPOP_RREPLY    4               /* RARP reply.  */
539 #define ARPOP_InREQUEST 8               /* InARP request.  */
540 #define ARPOP_InREPLY   9               /* InARP reply.  */
541 #define ARPOP_NAK       10              /* (ATM)ARP NAK.  */
542
543 /* See RFC 826 for protocol description.  ARP packets are variable
544    in size; the arphdr structure defines the fixed-length portion.
545    Protocol type values are the same as those for 10 Mb/s Ethernet.
546    It is followed by the variable-sized fields ar_sha, arp_spa,
547    arp_tha and arp_tpa in that order, according to the lengths
548    specified.  Field names used correspond to RFC 826.  */
549
550 struct arphdr
551   {
552     nint16_t ar_hrd;          /* Format of hardware address.  */
553     nint16_t ar_pro;          /* Format of protocol address.  */
554     nint8_t ar_hln;               /* Length of hardware address.  */
555     nint8_t ar_pln;               /* Length of protocol address.  */
556     nint16_t ar_op;           /* ARP opcode (command).  */
557 #if 0
558     /* Ethernet looks like this : This bit is variable sized
559        however...  */
560     nint8_t __ar_sha[ETH_ALEN];   /* Sender hardware address.  */
561     nint8_t __ar_sip[4];          /* Sender IP address.  */
562     nint8_t __ar_tha[ETH_ALEN];   /* Target hardware address.  */
563     nint8_t __ar_tip[4];          /* Target IP address.  */
564 #endif
565   };
566
567 /*
568  *      This is an Ethernet frame header.
569  */
570  
571 struct ethhdr {
572         nint8_t h_dest[ETH_ALEN];       /* destination eth addr */
573         nint8_t h_source[ETH_ALEN];     /* source ether addr    */
574         nint16_t          h_proto;                /* packet type ID field */
575 };
576
577 /*
578  * Ethernet Address Resolution Protocol.
579  *
580  * See RFC 826 for protocol description.  Structure below is adapted
581  * to resolving internet addresses.  Field names used correspond to
582  * RFC 826.
583  */
584 struct  ether_arp {
585         struct  arphdr ea_hdr;          /* fixed-size header */
586         nint8_t arp_sha[ETH_ALEN];     /* sender hardware address */
587         nint8_t arp_spa[4];            /* sender protocol address */
588         nint8_t arp_tha[ETH_ALEN];     /* target hardware address */
589         nint8_t arp_tpa[4];            /* target protocol address */
590 };
591 #define arp_hrd ea_hdr.ar_hrd
592 #define arp_pro ea_hdr.ar_pro
593 #define arp_hln ea_hdr.ar_hln
594 #define arp_pln ea_hdr.ar_pln
595 #define arp_op  ea_hdr.ar_op
596
597
598
599
600 /* ARP protocol HARDWARE identifiers. */
601 #define ARPHRD_NETROM   0               /* From KA9Q: NET/ROM pseudo. */
602 #define ARPHRD_ETHER    1               /* Ethernet 10/100Mbps.  */
603 #define ARPHRD_EETHER   2               /* Experimental Ethernet.  */
604 #define ARPHRD_AX25     3               /* AX.25 Level 2.  */
605 #define ARPHRD_PRONET   4               /* PROnet token ring.  */
606 #define ARPHRD_CHAOS    5               /* Chaosnet.  */
607 #define ARPHRD_IEEE802  6               /* IEEE 802.2 Ethernet/TR/TB.  */
608 #define ARPHRD_ARCNET   7               /* ARCnet.  */
609 #define ARPHRD_APPLETLK 8               /* APPLEtalk.  */
610 #define ARPHRD_DLCI     15              /* Frame Relay DLCI.  */
611 #define ARPHRD_ATM      19              /* ATM.  */
612 #define ARPHRD_METRICOM 23              /* Metricom STRIP (new IANA id).  */
613 #define ARPHRD_IEEE1394 24              /* IEEE 1394 IPv4 - RFC 2734.  */
614 #define ARPHRD_EUI64            27              /* EUI-64.  */
615 #define ARPHRD_INFINIBAND       32              /* InfiniBand.  */
616
617
618 #endif
619