peapod  0.1.0
EAPOL Proxy Daemon
parser.h
Go to the documentation of this file.
1 /**
2  * @file parser.h
3  * @brief Function prototypes for @p parser.y, config-related magic numbers and
4  * data structures
5  * @note @p parser.y is not documented with Doxygen.
6  */
7 #pragma once
8 
9 #include <stdint.h>
10 #include <net/if.h>
11 #include <linux/if_ether.h>
12 
13 /**
14  * @name Magic number definitions
15  * @{
16  */
17 #define IFACE_SET_MAC 0xff
18 #define TCI_NO_DOT1Q 0xef
19 #define TCI_UNTOUCHED 0xff
20 #define TCI_UNTOUCHED_16 0xffff
21 /** @} */
22 
23 /**
24  * @brief 802.1Q VLAN Tag Control Information
25  *
26  * Stores the three variable fields in a 4-byte 802.1Q VLAN tag.
27  */
28 struct tci_t {
29  uint8_t pcp; /**< @brief Priority Code Point */
30  uint8_t dei; /**< @brief Drop Eligible Indicator */
31  uint16_t vid; /**< @brief Identifier */
32 };
33 
34 /**
35  * @brief Bitmasks for filtering on EAPOL Packet Type or EAP Code.
36  *
37  * The respective ranges of EAPOL Packet Types and EAP Codes are 0-8 (requires 2
38  * bytes) and 1-4.
39  * @note Whether an instance of <tt>struct filter_t</tt> stores ingress or
40  * egress filters depends on whether its parent is a <tt>struct ingress_t</tt>
41  * or a <tt>struct egress_t</tt>.
42  */
43 struct filter_t {
44  uint16_t type; /**< @brief Filter on EAPOL Packet Type */
45  uint8_t code; /**< @brief Filter on EAP Code */
46 };
47 
48 /**
49  * @brief Scripts to execute on EAPOL Packet Type or EAP Code
50  *
51  * @p type and @p code are arrays of C strings. Each element contains either the
52  * path to an executable script or @p NULL.
53  *
54  * @note Whether an instance of <tt>struct filter_t</tt> stores ingress or
55  * egress scripts depends on whether its parent is a <tt>struct ingress_t</tt>
56  * or a <tt>struct egress_t</tt>.
57  * @note EAP Codes only range from 1-4, so @p packet[0] is always @p NULL.
58  */
59 struct action_t {
60  char *type[9]; /**< @brief Run script on EAPOL Packet Type */
61  char *code[5]; /**< @brief Run script on EAP Code */
62 };
63 
64 /** @brief Behavior during the ingress phase for an interface */
65 struct ingress_t {
66  struct action_t *action; /**< @brief Run script on ingress */
67  struct filter_t *filter; /**< @brief Filter on ingress */
68 };
69 
70 /** @brief Behavior during the egress phase for an interface */
71 struct egress_t {
72  struct tci_t *tci; /**< @brief Add/edit/remove VLAN tag on egress */
73  struct filter_t *filter; /**< @brief Filter on egress */
74  struct action_t *action; /**< @brief Run script on egress */
75 };
76 
77 /**
78  * @brief Represents a network interface and its associated config
79  *
80  * Also a node in a singly linked list of <tt>struct iface_t</tt> structures.
81  */
82 struct iface_t {
83  char name[IFNAMSIZ]; /**< @brief Network interface name. */
84  unsigned index; /**< @brief Interface index */
85  int mtu; /**< @brief Maximum Transmission Unit */
86  int skt; /**< @brief Raw socket bound to the interface */
87  unsigned recv_ctr; /**< @brief Number of EAPOL packets received */
88  unsigned send_ctr; /**< @brief Number of EAPOL packets sent */
89  struct ingress_t *ingress; /**< @brief Ingress options */
90  struct egress_t *egress; /**< @brief Egress options */
91  uint8_t promisc; /**< @brief Flag: Set promiscuous mode on @p skt? */
92  /**
93  * @brief A MAC address, plus a magic number
94  *
95  * During program startup, the current interface's MAC address will be
96  * changed to match the first @p ETH_ALEN bytes of this field, and the
97  * final byte of this field will be cleared.
98  *
99  * @note If this is set by the parser, its final byte will be set to
100  * <tt>IFACE_SET_MAC</tt>, and the @p set_mac_from field will not
101  * be set.
102  */
103  u_char set_mac[ETH_ALEN + 1];
104  /**
105  * @brief Index of another configured interface
106  *
107  * When that interface receives an EAPOL packet for the first time,
108  * the current interface's MAC address will be changed to match the
109  * packet's source MAC address, and this field will be cleared.
110  *
111  * @note If this is set by the parser, the @p set_mac field will not
112  * be set.
113  */
114  unsigned set_mac_from;
115  struct iface_t *next; /**< @brief Next node */
116 };
117 
118 struct iface_t *parse_config(const char *path, uint8_t *level);
119 void parser_print_ifaces(struct iface_t *list);
Represents a network interface and its associated config.
Definition: parser.h:82
struct filter_t * filter
Filter on egress.
Definition: parser.h:73
uint16_t type
Filter on EAPOL Packet Type.
Definition: parser.h:44
unsigned send_ctr
Number of EAPOL packets sent.
Definition: parser.h:88
struct action_t * action
Run script on egress.
Definition: parser.h:74
void parser_print_ifaces(struct iface_t *list)
uint16_t vid
Identifier.
Definition: parser.h:31
Behavior during the ingress phase for an interface.
Definition: parser.h:65
Behavior during the egress phase for an interface.
Definition: parser.h:71
struct iface_t * next
Next node.
Definition: parser.h:115
int skt
Raw socket bound to the interface.
Definition: parser.h:86
struct filter_t * filter
Filter on ingress.
Definition: parser.h:67
struct tci_t * tci
Add/edit/remove VLAN tag on egress.
Definition: parser.h:72
Scripts to execute on EAPOL Packet Type or EAP Code.
Definition: parser.h:59
802.1Q VLAN Tag Control Information
Definition: parser.h:28
struct iface_t * parse_config(const char *path, uint8_t *level)
struct action_t * action
Run script on ingress.
Definition: parser.h:66
unsigned set_mac_from
Index of another configured interface.
Definition: parser.h:114
Bitmasks for filtering on EAPOL Packet Type or EAP Code.
Definition: parser.h:43
uint8_t code
Filter on EAP Code.
Definition: parser.h:45
int mtu
Maximum Transmission Unit.
Definition: parser.h:85
unsigned recv_ctr
Number of EAPOL packets received.
Definition: parser.h:87
uint8_t dei
Drop Eligible Indicator.
Definition: parser.h:30
uint8_t promisc
Flag: Set promiscuous mode on skt?
Definition: parser.h:91
struct egress_t * egress
Egress options.
Definition: parser.h:90
uint8_t pcp
Priority Code Point.
Definition: parser.h:29
struct ingress_t * ingress
Ingress options.
Definition: parser.h:89
unsigned index
Interface index.
Definition: parser.h:84