peapod  0.1.0
EAPOL Proxy Daemon
packet.h
Go to the documentation of this file.
1 /**
2  * @file packet.h
3  * @brief Function prototypes for @p packet.c, EAPOL/EAP data structures
4  */
5 #pragma once
6 
7 #include <stdlib.h>
8 #include <linux/types.h>
9 #include "parser.h"
10 
11 /**
12  * @name EAPOL Packet Types
13  * @see IEEE Std 802.1X-2010 §11.3.2
14  * @{
15  */
16 #define EAPOL_EAP 0
17 #define EAPOL_START 1
18 #define EAPOL_LOGOFF 2
19 #define EAPOL_KEY 3
20 #define EAPOL_ENCAPSULATED_ASF_ALERT 4
21 #define EAPOL_MKA 5
22 #define EAPOL_ANNOUNCEMENT_GENERIC 6
23 #define EAPOL_ANNOUNCEMENT_SPECIFIC 7
24 #define EAPOL_ANNOUNCEMENT_REQ 8
25 /** @} */
26 
27 /**
28  * @name EAP Code
29  * @note RFC 2284 has been superseded by RFC 3748 and its successors,
30  * but the numeric Code values can only be found in the former.
31  * @see RFC 2284 §2.2
32  * @{
33  */
34 #define EAP_CODE_REQUEST 1
35 #define EAP_CODE_RESPONSE 2
36 #define EAP_CODE_SUCCESS 3
37 #define EAP_CODE_FAILURE 4
38 /** @} */
39 
40 /**
41  * @name EAP-Request/Response Type
42  *
43  * These apply if the EAP packet has Code of either Request or Response.
44  *
45  * @see RFC 3748 §5 for the initial Types (1-6, 254-255)
46  * @{
47  */
48 #define EAP_TYPE_IDENTITY 1
49 #define EAP_TYPE_NOTIFICATION 2
50 #define EAP_TYPE_NAK 3
51 #define EAP_TYPE_MD5_CHALLENGE 4
52 #define EAP_TYPE_OTP 5
53 #define EAP_TYPE_GTC 6
54 #define EAP_TYPE_TLS 13 /**< @see RFC 2716 §4.1 */
55 #define EAP_TYPE_SIM 18 /**< @see RFC 4186 §8.1 */
56 #define EAP_TYPE_TTLS 21 /**< @see RFC 5281 §9.1 */
57 #define EAP_TYPE_AKA_OLD 23 /**< @see RFC 4187 §8.1 */
58 #define EAP_TYPE_PEAP 25 /**< @see draft-josefsson-pppext-eap-tls-eap-06.txt §3.1 */
59 #define EAP_TYPE_MS_CHAP_V2 26 /**< @see draft-kamath-pppext-eap-mschapv2-02.txt §2 */
60 #define EAP_TYPE_MS_CHAP_V2_OLD 29 /**< @see draft-dpotter-pppext-eap-mschap-01.txt §4.1 */
61 #define EAP_TYPE_FAST 43 /**< @see RFC 4851 §4.1 */
62 #define EAP_TYPE_IKEV2 49 /**< @see RFC 5106 §8 */
63 #define EAP_TYPE_EXPANDED_TYPES 254
64 #define EAP_TYPE_EXPERIMENTAL_USE 255
65 /** @} */
66 
67 /**
68  * @name EAPOL-Key Descriptor Type
69  * @see IEEE Std 802.1X-2010 §11.9
70  * @{
71  */
72 #define EAPOL_KEY_TYPE_RC4 1 /**< @note Deprecated */
73 #define EAPOL_KEY_TYPE_IEEE_80211 2 /**< @see IEEE Std 802.11 */
74 /** @} */
75 
76 /**
77  * @brief A redefinition of <tt>struct tpacket_auxdata</tt> from
78  * <tt><linux/if_packet.h></tt>.
79  *
80  * We request a <tt>struct tpacket_auxdata</tt> from the kernel but interpret
81  * it as a <tt>struct packet_auxdata_t</tt> to (theoretically) allow compilation
82  * on earlier versions of Linux, as the @p tp_vlan_tpid member is called
83  * @p tp_padding in Linux <3.14.
84  *
85  * @see packet(7)
86  */
88  __u32 tp_status;
89  __u32 tp_len;
90  __u32 tp_snaplen;
91  __u16 tp_mac;
92  __u16 tp_net;
93  __u16 tp_vlan_tci;
94  __u16 tp_vlan_tpid;
95 };
96 
97 /**
98  * @brief EAPOL-EAP (EAP Packet) format.
99  * @see RFC 3748 §4
100  */
101 struct eapol_eap {
102  __u8 code; /**< @brief Packet Code */
103  __u8 id; /**< @brief Identifier */
104  __be16 len; /**< @brief Length */
105  __u8 type; /**< @brief Type (if Request or Response) */
106  //__u8 type_data[]; /**< @brief EAP Packet (variable length) */
107 }__attribute__((packed));
108 
109 /**
110  * @brief EAPOL-Key (Key Descriptor) format.
111  * @note Should only be used with RC4 key descriptors (now deprecated); however,
112  * the @p desc_type field is valid for all key descriptor types.
113  * @see IEEE Std 802.1X-2001 §7.6
114  * @see IEEE Std 802.1X-2010 §11.9
115  */
116 struct eapol_key {
117  __u8 desc_type; /**< @brief Descriptor Type */
118  __be16 key_len; /**< @brief Key Length */
119  __be64 replay_ctr; /**< @brief Replay Counter */
120  __u8 key_iv[16]; /**< @brief Key Initialization Vector */
121  __u8 key_index; /**< @brief Key Index */
122  __u8 key_sig[16]; /**< @brief Key Signature */
123  //__u8 key[]; /**< @brief Key (variable length) */
124 }__attribute__((packed));
125 
126 /**
127  * @brief EAPOL MAC Protocol Data Unit (MPDU) format.
128  * @see IEEE Std 802.1X-2010 §11.3
129  */
130 struct eapol_mpdu {
131  __be16 ether_type; /**< @brief PAE Ethernet Type */
132  __u8 proto_ver; /**< @brief Protocol Version */
133  __u8 type; /**< @brief Packet Type */
134  __be16 pkt_body_len; /**< @brief Packet Body Length */
135  /** @brief Packet Body */
136  union {
137  struct eapol_eap eap; /* EAPOL-EAP */
138  struct eapol_key key; /* EAPOL-Key */
139  /* other EAPOL Packet Types are not decoded */
140  }__attribute__((packed));
141 }__attribute__((packed));
142 
143 /** @brief Represents an EAPOL packet with some metadata already extracted. */
145  struct timeval tv; /**< @brief Packet timestamp */
146  struct iface_t *iface; /**< @brief Current interface */
147  struct iface_t *iface_orig; /**< @brief Interface on which packet was originally received */
148  ssize_t len; /**< @brief Current length */
149  ssize_t len_orig; /**< @brief Original length */
150  uint8_t h_dest[ETH_ALEN]; /**< @brief Destination MAC address */
151  uint8_t h_source[ETH_ALEN]; /**< @brief Source MAC address */
152  uint8_t vlan_valid; /**< @brief Flag: VLAN (802.1Q) tag currently present? */
153  uint8_t vlan_valid_orig; /**< @brief Flag: VLAN (802.1Q) tag originally present? */
154  struct tci_t tci; /**< @brief Current 802.1Q Tag Control Information */
155  struct tci_t tci_orig; /**< @brief Original 802.1Q Tag Control Information */
156  uint8_t type; /**< @brief EAPOL Packet Type */
157  uint8_t code; /**< @brief EAP Code */
158 };
159 
160 /**
161  * @brief Matches a single-byte value with a description.
162  *
163  * The value in question may be an EAPOL Packet Type, EAP Code,
164  * or EAP-Request/Reponse Type.
165  */
166 struct decode_t {
167  uint8_t val; /**< @brief Value */
168  char *desc; /**< @brief Description */
169 };
170 
171 /**
172  * @brief EAPOL Packet Type descriptions.
173  * @see IEEE Std 802.1X-2010 §11.3.2
174  */
175 static const struct decode_t eapol_types[] = {
176  { EAPOL_EAP, "EAPOL-EAP" },
177  { EAPOL_START, "EAPOL-Start" },
178  { EAPOL_LOGOFF, "EAPOL-Logoff" },
179  { EAPOL_KEY, "EAPOL-Key" },
180  { EAPOL_ENCAPSULATED_ASF_ALERT, "EAPOL-Encapsulated-ASF-Alert" },
181  { EAPOL_MKA, "EAPOL-MKA" },
182  { EAPOL_ANNOUNCEMENT_GENERIC, "EAPOL-Announcement (Generic)" },
183  { EAPOL_ANNOUNCEMENT_SPECIFIC, "EAPOL-Announcement (Specific)" },
184  { EAPOL_ANNOUNCEMENT_REQ, "EAPOL-Announcement-Req" },
185  { 0, NULL }
186 };
187 
188 /**
189  * @brief EAP Code descriptions.
190  * @see RFC 2284 §2.2
191  */
192 static const struct decode_t eap_codes[] = {
193  { EAP_CODE_REQUEST, "Request" },
194  { EAP_CODE_RESPONSE, "Response" },
195  { EAP_CODE_SUCCESS, "Success" },
196  { EAP_CODE_FAILURE, "Failure" },
197  { 0, NULL }
198 };
199 
200 /**
201  * @brief EAP-Request/Response Type descriptions.
202  *
203  * The text of the descriptions is as stated in the relevant RFCs.
204  */
205 static const struct decode_t eap_types[] = {
206  { EAP_TYPE_IDENTITY, "Identity" },
207  { EAP_TYPE_NOTIFICATION, "Notification" },
208  { EAP_TYPE_NAK, "Nak (Response only)" },
209  { EAP_TYPE_MD5_CHALLENGE, "MD5-Challenge" },
210  { EAP_TYPE_OTP, "One Time Password (OTP)" },
211  { EAP_TYPE_GTC, "Generic Token Card (GTC)" },
212  { EAP_TYPE_TLS, "EAP TLS" },
213  { EAP_TYPE_SIM, "EAP-SIM" },
214  { EAP_TYPE_TTLS, "EAP-TTLS" },
215  { EAP_TYPE_AKA_OLD, "EAP-AKA" },
216  { EAP_TYPE_PEAP, "PEAP" },
217  { EAP_TYPE_MS_CHAP_V2, "EAP MS-CHAP-V2" },
218  { EAP_TYPE_MS_CHAP_V2_OLD, "EAP MS-CHAP V2" },
219  { EAP_TYPE_FAST, "EAP-FAST" },
220  { EAP_TYPE_IKEV2, "EAP-IKEv2"},
221  { EAP_TYPE_EXPANDED_TYPES, "Expanded Types" },
222  { EAP_TYPE_EXPERIMENTAL_USE, "Experimental use" },
223  { 0, NULL }
224 };
225 
226 /**
227  * @brief Descriptions for EAPOL-Key Descriptor Type.
228  * @see IEEE Std 802.1X-2010 §11.9
229  */
230 static const struct decode_t eapol_key_types[] = {
231  { EAPOL_KEY_TYPE_RC4, "RC4" },
232  { EAPOL_KEY_TYPE_IEEE_80211, "IEEE 802.11" },
233  { 0, NULL }
234 };
235 
236 void packet_init(struct iface_t *ifaces);
237 uint8_t *packet_buf(struct peapod_packet packet, uint8_t orig);
238 char* packet_decode(uint8_t val, const struct decode_t *decode);
239 uint32_t packet_tcitonl(struct tci_t tci);
240 int packet_send(struct peapod_packet packet, struct iface_t *iface);
241 struct peapod_packet packet_recvmsg(struct iface_t *iface);
__be16 len
Length.
Definition: packet.h:104
__u32 tp_snaplen
Definition: packet.h:90
__u8 type
Packet Type.
Definition: packet.h:133
uint8_t vlan_valid
Flag: VLAN (802.1Q) tag currently present?
Definition: packet.h:152
struct iface_t * ifaces
Interface list.
Definition: peapod.c:85
#define EAP_TYPE_TTLS
Definition: packet.h:56
#define EAP_TYPE_TLS
Definition: packet.h:54
#define EAP_CODE_FAILURE
Definition: packet.h:37
#define EAP_TYPE_OTP
Definition: packet.h:52
char * packet_decode(uint8_t val, const struct decode_t *decode)
Decode a byte in an EAPOL packet to a C string.
Definition: packet.c:309
Represents a network interface and its associated config.
Definition: parser.h:82
#define EAP_TYPE_IDENTITY
Definition: packet.h:48
__u8 proto_ver
Protocol Version.
Definition: packet.h:132
char * desc
Description.
Definition: packet.h:168
#define EAP_TYPE_EXPERIMENTAL_USE
Definition: packet.h:64
__u32 tp_status
Definition: packet.h:88
static const struct decode_t eap_types[]
EAP-Request/Response Type descriptions.
Definition: packet.h:205
uint8_t code
EAP Code.
Definition: packet.h:157
#define EAP_CODE_RESPONSE
Definition: packet.h:35
#define EAP_TYPE_SIM
Definition: packet.h:55
Represents an EAPOL packet with some metadata already extracted.
Definition: packet.h:144
__u16 tp_mac
Definition: packet.h:91
__u8 desc_type
Descriptor Type.
Definition: packet.h:117
uint8_t * packet_buf(struct peapod_packet packet, uint8_t orig)
Return a pointer to a raw EAPOL packet.
Definition: packet.c:253
#define EAPOL_ENCAPSULATED_ASF_ALERT
Definition: packet.h:20
__u16 tp_net
Definition: packet.h:92
__u16 tp_vlan_tpid
Definition: packet.h:94
__be64 replay_ctr
Replay Counter.
Definition: packet.h:119
#define EAP_TYPE_IKEV2
Definition: packet.h:62
EAPOL MAC Protocol Data Unit (MPDU) format.
Definition: packet.h:130
__u8 key_index
Key Index.
Definition: packet.h:121
#define EAP_CODE_REQUEST
Definition: packet.h:34
Function prototypes for parser.y, config-related magic numbers and data structures.
#define EAPOL_LOGOFF
Definition: packet.h:18
#define EAPOL_ANNOUNCEMENT_SPECIFIC
Definition: packet.h:23
A redefinition of struct tpacket_auxdata from <linux/if_packet.h>.
Definition: packet.h:87
__be16 pkt_body_len
Packet Body Length.
Definition: packet.h:134
#define EAPOL_KEY_TYPE_RC4
Definition: packet.h:72
#define EAP_TYPE_GTC
Definition: packet.h:53
EAPOL-EAP (EAP Packet) format.
Definition: packet.h:101
#define EAP_TYPE_NAK
Definition: packet.h:50
#define EAPOL_ANNOUNCEMENT_GENERIC
Definition: packet.h:22
void packet_init(struct iface_t *ifaces)
Allocate the main buffer for the EAPOL packet.
Definition: packet.c:209
struct iface_t * iface
Current interface.
Definition: packet.h:146
802.1Q VLAN Tag Control Information
Definition: parser.h:28
#define EAP_CODE_SUCCESS
Definition: packet.h:36
struct iface_t * iface_orig
Interface on which packet was originally received.
Definition: packet.h:147
__be16 ether_type
PAE Ethernet Type.
Definition: packet.h:131
#define EAP_TYPE_EXPANDED_TYPES
Definition: packet.h:63
#define EAPOL_KEY
Definition: packet.h:19
#define EAPOL_START
Definition: packet.h:17
__u8 code
Packet Code.
Definition: packet.h:102
EAPOL-Key (Key Descriptor) format.
Definition: packet.h:116
uint32_t packet_tcitonl(struct tci_t tci)
Convert a struct tci_t to a 4-byte 802.1Q tag.
Definition: packet.c:286
#define EAP_TYPE_MD5_CHALLENGE
Definition: packet.h:51
uint8_t val
Value.
Definition: packet.h:167
Matches a single-byte value with a description.
Definition: packet.h:166
#define EAPOL_ANNOUNCEMENT_REQ
Definition: packet.h:24
#define EAPOL_EAP
Definition: packet.h:16
static const struct decode_t eap_codes[]
EAP Code descriptions.
Definition: packet.h:192
__u8 type
Type (if Request or Response)
Definition: packet.h:105
#define EAP_TYPE_MS_CHAP_V2
Definition: packet.h:59
#define EAP_TYPE_FAST
Definition: packet.h:61
__be16 key_len
Key Length.
Definition: packet.h:118
#define EAPOL_KEY_TYPE_IEEE_80211
Definition: packet.h:73
uint8_t type
EAPOL Packet Type.
Definition: packet.h:156
__u32 tp_len
Definition: packet.h:89
#define EAP_TYPE_AKA_OLD
Definition: packet.h:57
__u16 tp_vlan_tci
Definition: packet.h:93
static const struct decode_t eapol_types[]
EAPOL Packet Type descriptions.
Definition: packet.h:175
static void decode(struct peapod_packet pkt)
Log metadata for a struct peapod_packet in a tcpdump-like format.
Definition: packet.c:122
static const struct decode_t eapol_key_types[]
Descriptions for EAPOL-Key Descriptor Type.
Definition: packet.h:230
#define EAP_TYPE_MS_CHAP_V2_OLD
Definition: packet.h:60
__u8 id
Identifier.
Definition: packet.h:103
#define EAPOL_MKA
Definition: packet.h:21
#define EAP_TYPE_NOTIFICATION
Definition: packet.h:49
ssize_t len
Current length.
Definition: packet.h:148
int packet_send(struct peapod_packet packet, struct iface_t *iface)
Send an EAPOL packet on a network interface.
Definition: packet.c:331
ssize_t len_orig
Original length.
Definition: packet.h:149
uint8_t vlan_valid_orig
Flag: VLAN (802.1Q) tag originally present?
Definition: packet.h:153
#define EAP_TYPE_PEAP
Definition: packet.h:58