peapod
0.1.0
EAPOL Proxy Daemon
|
EAPOL packet operations. More...
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include "args.h"
#include "log.h"
#include "packet.h"
#include "process.h"
Functions | |
static void | dump (struct peapod_packet packet) |
Log a hexadecimal dump of a struct peapod_packet More... | |
static void | decode (struct peapod_packet packet) |
Log metadata for a struct peapod_packet in a tcpdump -like format. More... | |
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... | |
uint32_t | packet_tcitonl (struct tci_t tci) |
Convert a struct tci_t to a 4-byte 802.1Q tag. More... | |
char * | packet_decode (uint8_t val, const struct decode_t *decode) |
Decode a byte in an EAPOL packet to a C string. 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 | |
union { | |
struct cmsghdr cmsg | |
uint8_t buf [CMSG_SPACE(sizeof(struct packet_auxdata_t))] | |
} | cmsg_buf |
Buffer for receiving a struct packet_auxdata_t from the kernel via recvmsg(2) More... | |
static struct msghdr | msg |
A struct msghdr for recvmsg(2) More... | |
struct args_t | args |
Program arguments data structure. More... | |
EAPOL packet buffer | |
The size of this buffer is normally 1518 bytes given a 1500-byte MTU, to accommodate the standard 1514-byte Ethernet frame size plus a 4-byte 802.1Q tag. We use an This allows us to do things like adding, modifying, or removing an 802.1Q tag for a proxied packet on a per-egress-interface basis. We simply reconstruct/modify the first 16 bytes of this buffer as needed, then call | |
static uint8_t * | pkt_buf = NULL |
Main EAPOL packet buffer. More... | |
static int | pkt_buf_size = 0 |
Normally 1518 bytes. More... | |
uint8_t * | mpdu_buf = NULL |
The EAPOL MPDU. More... | |
int | mpdu_buf_size = 0 |
Normally 1502 bytes. More... | |
EAPOL packet operations.
|
static |
Log a hexadecimal dump of a struct peapod_packet
packet | A struct peapod_packet representing an EAPOL packet |
|
static |
Log metadata for a struct peapod_packet
in a tcpdump
-like format.
packet | A struct peapod_packet representing an EAPOL packet |
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.
ifaces | Pointer to a list of struct iface_t structures representing network interfaces |
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. 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:
The result may then be used by the caller to (hex)dump, Base64-encode, and/or send the packet.
packet | A struct peapod_packet representing an EAPOL packet |
orig | Flag: Reconstruct original packet as seen on ingress interface? |
uint32_t packet_tcitonl | ( | struct tci_t | tci | ) |
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:
val | Value of the relevant byte to decode |
decode | Pointer to a struct decode_t matching field values with descriptions |
decode
. int packet_send | ( | struct peapod_packet | packet, |
struct iface_t * | iface | ||
) |
Send an EAPOL packet on a network interface.
May execute an egress script.
packet | A struct peapod_packet representing an EAPOL packet |
iface | Pointer to a struct iface_t representing an interface |
struct peapod_packet packet_recvmsg | ( | struct iface_t * | iface | ) |
Receive an EAPOL packet on a network interface.
struct peapod_packet
representing an EAPOL packet with its len
field set to one of the following:
|
static |
Main EAPOL packet buffer.
|
static |
Normally 1518 bytes.
uint8_t* mpdu_buf = NULL |
The EAPOL MPDU.
Points to byte 16 of the main EAPOL packet buffer, and thereby to the EAPOL EtherType (0x888e) followed by the MTU (normally up to 1500 bytes).
int mpdu_buf_size = 0 |
Normally 1502 bytes.
struct cmsghdr cmsg |
uint8_t buf[CMSG_SPACE(sizeof(struct packet_auxdata_t))] |
union { ... } cmsg_buf |
Buffer for receiving a struct packet_auxdata_t
from the kernel via recvmsg(2)
struct tpacket_auxdata
socket(7)
, "Socket options"
|
static |
struct args_t args |
Program arguments data structure.