peapod  0.1.0
EAPOL Proxy Daemon
Data Structures | Functions | Variables
packet.h File Reference

Function prototypes for packet.c, EAPOL/EAP data structures. More...

#include <stdlib.h>
#include <linux/types.h>
#include "parser.h"
Include dependency graph for packet.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  packet_auxdata_t
 A redefinition of struct tpacket_auxdata from <linux/if_packet.h>. More...
 
struct  eapol_eap
 EAPOL-EAP (EAP Packet) format. More...
 
struct  eapol_key
 EAPOL-Key (Key Descriptor) format. More...
 
struct  eapol_mpdu
 EAPOL MAC Protocol Data Unit (MPDU) format. More...
 
struct  peapod_packet
 Represents an EAPOL packet with some metadata already extracted. More...
 
struct  decode_t
 Matches a single-byte value with a description. More...
 

Macros

EAPOL Packet Types
See also
IEEE Std 802.1X-2010 §11.3.2
#define EAPOL_EAP   0
 
#define EAPOL_START   1
 
#define EAPOL_LOGOFF   2
 
#define EAPOL_KEY   3
 
#define EAPOL_ENCAPSULATED_ASF_ALERT   4
 
#define EAPOL_MKA   5
 
#define EAPOL_ANNOUNCEMENT_GENERIC   6
 
#define EAPOL_ANNOUNCEMENT_SPECIFIC   7
 
#define EAPOL_ANNOUNCEMENT_REQ   8
 
EAP Code
Note
RFC 2284 has been superseded by RFC 3748 and its successors, but the numeric Code values can only be found in the former.
See also
RFC 2284 §2.2
#define EAP_CODE_REQUEST   1
 
#define EAP_CODE_RESPONSE   2
 
#define EAP_CODE_SUCCESS   3
 
#define EAP_CODE_FAILURE   4
 
EAP-Request/Response Type

These apply if the EAP packet has Code of either Request or Response.

See also
RFC 3748 §5 for the initial Types (1-6, 254-255)
#define EAP_TYPE_IDENTITY   1
 
#define EAP_TYPE_NOTIFICATION   2
 
#define EAP_TYPE_NAK   3
 
#define EAP_TYPE_MD5_CHALLENGE   4
 
#define EAP_TYPE_OTP   5
 
#define EAP_TYPE_GTC   6
 
#define EAP_TYPE_TLS   13
 
#define EAP_TYPE_SIM   18
 
#define EAP_TYPE_TTLS   21
 
#define EAP_TYPE_AKA_OLD   23
 
#define EAP_TYPE_PEAP   25
 
#define EAP_TYPE_MS_CHAP_V2   26
 
#define EAP_TYPE_MS_CHAP_V2_OLD   29
 
#define EAP_TYPE_FAST   43
 
#define EAP_TYPE_IKEV2   49
 
#define EAP_TYPE_EXPANDED_TYPES   254
 
#define EAP_TYPE_EXPERIMENTAL_USE   255
 
EAPOL-Key Descriptor Type
See also
IEEE Std 802.1X-2010 §11.9
#define EAPOL_KEY_TYPE_RC4   1
 
#define EAPOL_KEY_TYPE_IEEE_80211   2
 

Functions

void packet_init (struct iface_t *ifaces)
 Allocate the main buffer for the EAPOL packet. More...
 
uint8_t * packet_buf (struct peapod_packet packet, uint8_t orig)
 Return a pointer to a raw EAPOL packet. More...
 
char * packet_decode (uint8_t val, const struct decode_t *decode)
 Decode a byte in an EAPOL packet to a C string. More...
 
uint32_t packet_tcitonl (struct tci_t tci)
 Convert a struct tci_t to a 4-byte 802.1Q tag. More...
 
int packet_send (struct peapod_packet packet, struct iface_t *iface)
 Send an EAPOL packet on a network interface. More...
 
struct peapod_packet packet_recvmsg (struct iface_t *iface)
 Receive an EAPOL packet on a network interface. More...
 

Variables

static const struct decode_t eapol_types []
 EAPOL Packet Type descriptions. More...
 
static const struct decode_t eap_codes []
 EAP Code descriptions. More...
 
static const struct decode_t eap_types []
 EAP-Request/Response Type descriptions. More...
 
static const struct decode_t eapol_key_types []
 Descriptions for EAPOL-Key Descriptor Type. More...
 

Detailed Description

Function prototypes for packet.c, EAPOL/EAP data structures.

Macro Definition Documentation

#define EAPOL_EAP   0
#define EAPOL_START   1
#define EAPOL_LOGOFF   2
#define EAPOL_KEY   3
#define EAPOL_ENCAPSULATED_ASF_ALERT   4
#define EAPOL_MKA   5
#define EAPOL_ANNOUNCEMENT_GENERIC   6
#define EAPOL_ANNOUNCEMENT_SPECIFIC   7
#define EAPOL_ANNOUNCEMENT_REQ   8
#define EAP_CODE_REQUEST   1
#define EAP_CODE_RESPONSE   2
#define EAP_CODE_SUCCESS   3
#define EAP_CODE_FAILURE   4
#define EAP_TYPE_IDENTITY   1
#define EAP_TYPE_NOTIFICATION   2
#define EAP_TYPE_NAK   3
#define EAP_TYPE_MD5_CHALLENGE   4
#define EAP_TYPE_OTP   5
#define EAP_TYPE_GTC   6
#define EAP_TYPE_TLS   13
See also
RFC 2716 §4.1
#define EAP_TYPE_SIM   18
See also
RFC 4186 §8.1
#define EAP_TYPE_TTLS   21
See also
RFC 5281 §9.1
#define EAP_TYPE_AKA_OLD   23
See also
RFC 4187 §8.1
#define EAP_TYPE_PEAP   25
See also
draft-josefsson-pppext-eap-tls-eap-06.txt §3.1
#define EAP_TYPE_MS_CHAP_V2   26
See also
draft-kamath-pppext-eap-mschapv2-02.txt §2
#define EAP_TYPE_MS_CHAP_V2_OLD   29
See also
draft-dpotter-pppext-eap-mschap-01.txt §4.1
#define EAP_TYPE_FAST   43
See also
RFC 4851 §4.1
#define EAP_TYPE_IKEV2   49
See also
RFC 5106 §8
#define EAP_TYPE_EXPANDED_TYPES   254
#define EAP_TYPE_EXPERIMENTAL_USE   255
#define EAPOL_KEY_TYPE_RC4   1
Note
Deprecated
#define EAPOL_KEY_TYPE_IEEE_80211   2
See also
IEEE Std 802.11

Function Documentation

void packet_init ( struct iface_t ifaces)

Allocate the main buffer for the EAPOL packet.

The size of the buffer is determined according to the highest MTU of the network interfaces used by the program.

Parameters
ifacesPointer to a list of struct iface_t structures representing network interfaces
Note
valgrind claims the memory allocated here is "possibly lost". Ignore it; we're "doing unusual things with pointers that could cause them to point into the middle of an allocated block". Quite deliberately so.
See also
http://valgrind.org/docs/manual/faq.html#faq.deflost
uint8_t* packet_buf ( struct peapod_packet  packet,
uint8_t  orig 
)

Return a pointer to a raw EAPOL packet.

Rewrites the first 16 bytes of the main packet buffer. The result shall point to the beginning of a raw EAPOL packet that is either:

  1. the original packet, including the VLAN tag, as it appeared when it was captured on the ingress interface, or
  2. the processed packet, possibly with original VLAN tag removed or tag fields changed according to interface egress options, that should be sent out on a given egress interface.

The result may then be used by the caller to (hex)dump, Base64-encode, and/or send the packet.

Parameters
packetA struct peapod_packet representing an EAPOL packet
origFlag: Reconstruct original packet as seen on ingress interface?
Returns
Pointer to the beginning of a complete EAPOL packet
char* packet_decode ( uint8_t  val,
const struct decode_t decode 
)

Decode a byte in an EAPOL packet to a C string.

The byte may be one of the following:

  1. the Type field of an EAPOL packet,
  2. the Code field of an EAP packet encapsulated in an EAPOL-EAP packet, or
  3. the Type field of an EAP-Request or EAP-Response encapsulated in an EAP packet.
Parameters
valValue of the relevant byte to decode
decodePointer to a struct decode_t matching field values with descriptions
Returns
A description, or "Unknown" if the value does not have a corresponding description in decode.
uint32_t packet_tcitonl ( struct tci_t  tci)

Convert a struct tci_t to a 4-byte 802.1Q tag.

Parameters
tciA struct tci_t representing an 802.1Q TCI
Returns
An unsigned 32-bit integer in network order
int packet_send ( struct peapod_packet  packet,
struct iface_t iface 
)

Send an EAPOL packet on a network interface.

May execute an egress script.

Parameters
packetA struct peapod_packet representing an EAPOL packet
ifacePointer to a struct iface_t representing an interface
Returns
The number of bytes successfully sent
struct peapod_packet packet_recvmsg ( struct iface_t iface)

Receive an EAPOL packet on a network interface.

Returns
A struct peapod_packet representing an EAPOL packet with its len field set to one of the following:
  1. the number of bytes successfully received (if at least 60),
  2. -1 if an error occurred while receiving,
  3. -2 if fewer than 60 bytes were received (i.e. the EAPOL packet was smaller than the minimum Ethernet frame size of 64 bytes, as the 4-byte FCS is not included), or
  4. -3 if the packet was too big to fit in the main EAPOL packet buffer (i.e. the MTU was ignored).
Note
If at least 60 bytes were successfully received, the result will have Ethernet, EAPOL, and EAP metadata in its other fields.

Variable Documentation

const struct decode_t eapol_types[]
static
Initial value:
= {
{ EAPOL_EAP, "EAPOL-EAP" },
{ EAPOL_START, "EAPOL-Start" },
{ EAPOL_LOGOFF, "EAPOL-Logoff" },
{ EAPOL_KEY, "EAPOL-Key" },
{ EAPOL_ENCAPSULATED_ASF_ALERT, "EAPOL-Encapsulated-ASF-Alert" },
{ EAPOL_MKA, "EAPOL-MKA" },
{ EAPOL_ANNOUNCEMENT_GENERIC, "EAPOL-Announcement (Generic)" },
{ EAPOL_ANNOUNCEMENT_SPECIFIC, "EAPOL-Announcement (Specific)" },
{ EAPOL_ANNOUNCEMENT_REQ, "EAPOL-Announcement-Req" },
{ 0, NULL }
}
#define EAPOL_ENCAPSULATED_ASF_ALERT
Definition: packet.h:20
#define EAPOL_LOGOFF
Definition: packet.h:18
#define EAPOL_ANNOUNCEMENT_SPECIFIC
Definition: packet.h:23
#define EAPOL_ANNOUNCEMENT_GENERIC
Definition: packet.h:22
#define EAPOL_KEY
Definition: packet.h:19
#define EAPOL_START
Definition: packet.h:17
#define EAPOL_ANNOUNCEMENT_REQ
Definition: packet.h:24
#define EAPOL_EAP
Definition: packet.h:16
#define EAPOL_MKA
Definition: packet.h:21

EAPOL Packet Type descriptions.

See also
IEEE Std 802.1X-2010 §11.3.2
const struct decode_t eap_codes[]
static
Initial value:
= {
{ EAP_CODE_REQUEST, "Request" },
{ EAP_CODE_RESPONSE, "Response" },
{ EAP_CODE_SUCCESS, "Success" },
{ EAP_CODE_FAILURE, "Failure" },
{ 0, NULL }
}
#define EAP_CODE_FAILURE
Definition: packet.h:37
#define EAP_CODE_RESPONSE
Definition: packet.h:35
#define EAP_CODE_REQUEST
Definition: packet.h:34
#define EAP_CODE_SUCCESS
Definition: packet.h:36

EAP Code descriptions.

See also
RFC 2284 §2.2
const struct decode_t eap_types[]
static
Initial value:
= {
{ EAP_TYPE_IDENTITY, "Identity" },
{ EAP_TYPE_NOTIFICATION, "Notification" },
{ EAP_TYPE_NAK, "Nak (Response only)" },
{ EAP_TYPE_MD5_CHALLENGE, "MD5-Challenge" },
{ EAP_TYPE_OTP, "One Time Password (OTP)" },
{ EAP_TYPE_GTC, "Generic Token Card (GTC)" },
{ EAP_TYPE_TLS, "EAP TLS" },
{ EAP_TYPE_SIM, "EAP-SIM" },
{ EAP_TYPE_TTLS, "EAP-TTLS" },
{ EAP_TYPE_AKA_OLD, "EAP-AKA" },
{ EAP_TYPE_PEAP, "PEAP" },
{ EAP_TYPE_MS_CHAP_V2, "EAP MS-CHAP-V2" },
{ EAP_TYPE_MS_CHAP_V2_OLD, "EAP MS-CHAP V2" },
{ EAP_TYPE_FAST, "EAP-FAST" },
{ EAP_TYPE_IKEV2, "EAP-IKEv2"},
{ EAP_TYPE_EXPANDED_TYPES, "Expanded Types" },
{ EAP_TYPE_EXPERIMENTAL_USE, "Experimental use" },
{ 0, NULL }
}
#define EAP_TYPE_TTLS
Definition: packet.h:56
#define EAP_TYPE_TLS
Definition: packet.h:54
#define EAP_TYPE_OTP
Definition: packet.h:52
#define EAP_TYPE_IDENTITY
Definition: packet.h:48
#define EAP_TYPE_EXPERIMENTAL_USE
Definition: packet.h:64
#define EAP_TYPE_SIM
Definition: packet.h:55
#define EAP_TYPE_IKEV2
Definition: packet.h:62
#define EAP_TYPE_GTC
Definition: packet.h:53
#define EAP_TYPE_NAK
Definition: packet.h:50
#define EAP_TYPE_EXPANDED_TYPES
Definition: packet.h:63
#define EAP_TYPE_MD5_CHALLENGE
Definition: packet.h:51
#define EAP_TYPE_MS_CHAP_V2
Definition: packet.h:59
#define EAP_TYPE_FAST
Definition: packet.h:61
#define EAP_TYPE_AKA_OLD
Definition: packet.h:57
#define EAP_TYPE_MS_CHAP_V2_OLD
Definition: packet.h:60
#define EAP_TYPE_NOTIFICATION
Definition: packet.h:49
#define EAP_TYPE_PEAP
Definition: packet.h:58

EAP-Request/Response Type descriptions.

The text of the descriptions is as stated in the relevant RFCs.

const struct decode_t eapol_key_types[]
static
Initial value:
= {
{ EAPOL_KEY_TYPE_RC4, "RC4" },
{ EAPOL_KEY_TYPE_IEEE_80211, "IEEE 802.11" },
{ 0, NULL }
}
#define EAPOL_KEY_TYPE_RC4
Definition: packet.h:72
#define EAPOL_KEY_TYPE_IEEE_80211
Definition: packet.h:73

Descriptions for EAPOL-Key Descriptor Type.

See also
IEEE Std 802.1X-2010 §11.9