Click
Loading...
Searching...
No Matches
ether.h
1/* -*- mode: c; c-basic-offset: 4 -*- */
2#ifndef CLICKNET_ETHER_H
3#define CLICKNET_ETHER_H
4
5/*
6 * <clicknet/ether.h> -- Ethernet and ARP headers, based on one of the BSDs.
7 *
8 * Relevant RFCs include:
9 * RFC826 Ethernet Address Resolution Protocol: or, Converting Network
10 * Protocol Addresses to 48.bit Ethernet Address for Transmission
11 * on Ethernet Hardware
12 * RFC894 Standard for the transmission of IP datagrams over Ethernet
13 * networks
14 * Also see the relevant IEEE 802 standards.
15 */
16
17struct click_ether {
18 uint8_t ether_dhost[6]; /* 0-5 Ethernet destination address */
19 uint8_t ether_shost[6]; /* 6-11 Ethernet source address */
20 uint16_t ether_type; /* 12-13 Ethernet protocol */
21} CLICK_SIZE_PACKED_ATTRIBUTE;
22
23#define ETHERTYPE_IP 0x0800
24#define ETHERTYPE_ARP 0x0806
25#define ETHERTYPE_TRAIL 0x1000
26#define ETHERTYPE_8021Q 0x8100
27#define ETHERTYPE_IP6 0x86DD
28#define ETHERTYPE_MACCONTROL 0x8808
29#define ETHERTYPE_PPPOE_DISC 0x8863
30#define ETHERTYPE_PPPOE_SESSION 0x8864
31#define ETHERTYPE_GRID 0x7fff /* wvlan_cs driver won't transmit frames with high bit of protocol number set */
32
33struct click_arp { /* Offsets relative to ARP (Ethernet) header */
34 uint16_t ar_hrd; /* 0-1 (14-15) hardware address format */
35#define ARPHRD_ETHER 1 /* Ethernet 10Mbps */
36#define ARPHRD_IEEE802 6 /* token ring */
37#define ARPHRD_ARCNET 7 /* Arcnet */
38#define ARPHRD_FRELAY 15 /* frame relay */
39#define ARPHRD_STRIP 23 /* Ricochet Starmode Radio */
40#define ARPHRD_IEEE1394 24 /* IEEE 1394 (FireWire) */
41#define ARPHRD_80211 801 /* IEEE 802.11 (wifi) */
42 uint16_t ar_pro; /* 2-3 (16-17) protocol address format */
43 uint8_t ar_hln; /* 4 (18) hardware address length */
44 uint8_t ar_pln; /* 5 (19) protocol address length */
45 uint16_t ar_op; /* 6-7 (20-21) opcode (command) */
46#define ARPOP_REQUEST 1 /* ARP request */
47#define ARPOP_REPLY 2 /* ARP reply */
48#define ARPOP_REVREQUEST 3 /* reverse request: hw->proto */
49#define ARPOP_REVREPLY 4 /* reverse reply */
50#define ARPOP_INVREQUEST 8 /* peer identification req */
51#define ARPOP_INVREPLY 9 /* peer identification reply */
52};
53
54struct click_ether_arp {
55 struct click_arp ea_hdr; /* 0-7 (14-21) fixed-size ARP header */
56 uint8_t arp_sha[6]; /* 8-13 (22-27) sender hardware address */
57 uint8_t arp_spa[4]; /* 14-17 (28-31) sender protocol address */
58 uint8_t arp_tha[6]; /* 18-23 (32-37) target hardware address */
59 uint8_t arp_tpa[4]; /* 24-27 (38-41) target protocol address */
60};
61
62
63/* Ethernet with VLAN (802.1q) */
64
65struct click_ether_vlan {
66 uint8_t ether_dhost[6]; /* 0-5 Ethernet source address */
67 uint8_t ether_shost[6]; /* 6-11 Ethernet destination address */
68 uint16_t ether_vlan_proto; /* 12-13 == ETHERTYPE_8021Q */
69 uint16_t ether_vlan_tci; /* 14-15 tag control information */
70 uint16_t ether_vlan_encap_proto; /* 16-17 Ethernet protocol */
71} CLICK_SIZE_PACKED_ATTRIBUTE;
72
73
74/* Ethernet MAC control (802.3) */
75
76struct click_ether_macctl {
77 uint16_t ether_macctl_opcode;
78 uint16_t ether_macctl_param;
79 uint8_t ether_macctl_reserved[42];
80};
81
82#define ETHER_MACCTL_OP_PAUSE 0x0001
83
84
85#define ND_SOL 0x0087 /* Neighborhood Solicitation Message Type */
86#define ND_ADV 0x0088 /* Neighborhood Advertisement Message Type */
87
88/* define structure of Neighborhood Solicitation Message */
89struct click_nd_sol {
90 uint8_t type;
91 uint8_t code;
92 uint16_t checksum;
93 uint32_t reserved;
94 uint8_t nd_tpa[16];
95 uint8_t option_type; /*option type: 1 (source link-layer add) */
96 uint8_t option_length; /*option length: 1 (in units of 8 octets) */
97 uint8_t nd_sha[6]; /*source link-layer address */
98};
99
100/* define structure of Neighborhood Advertisement Message -reply to multicast neighborhood solitation message */
101struct click_nd_adv {
102 uint8_t type;
103 uint8_t code;
104 uint16_t checksum;
105 uint8_t flags; /* bit 1: sender_is_router
106 bit 2: solicited
107 bit 3: override
108 all other bits should be zero */
109 uint8_t reserved[3];
110 uint8_t nd_tpa[16];
111 uint8_t option_type; /* option type: 2 (target link-layer add) */
112 uint8_t option_length; /* option length: 1 (in units of 8 octets) */
113 uint8_t nd_tha[6]; /* source link-layer address */
114};
115
116
117/* define structure of Neighborhood Advertisement Message - reply to unicast neighborhood solitation message */
118struct click_nd_adv2 {
119 uint8_t type;
120 uint8_t code;
121 uint16_t checksum;
122 uint8_t flags; /* bit 1: sender_is_router
123 bit 2: solicited
124 bit 3: override
125 all other bits should be zero */
126 uint8_t reserved[3];
127 uint8_t nd_tpa[16];
128};
129
130#endif