cpfsyslog/src/pfparser.h

117 lines
2.2 KiB
C
Raw Permalink Normal View History

2018-07-03 13:41:17 -07:00
#include <stdlib.h>
2018-07-04 17:09:03 -07:00
#include <json-c/json.h>
2018-07-03 13:41:17 -07:00
2018-07-14 21:02:21 -07:00
#define IFACE_LEN 16
2018-05-15 23:30:46 -07:00
typedef enum pf_hit_reason {
pf_hit_match,
pf_hit_other
} pf_hit_reason;
2018-05-28 12:48:37 -07:00
const static char* pfhrstr[] __attribute__ ((unused)) =
{[pf_hit_match] = "match",
[pf_hit_other] = "other"};
2018-05-15 23:30:46 -07:00
typedef enum pf_hit_action {
pf_hit_block,
pf_hit_pass
} pf_hit_action;
2018-05-28 12:48:37 -07:00
const static char* pfhastr[] __attribute__ ((unused)) =
{[pf_hit_block] = "block",
[pf_hit_pass] = "pass"};
2018-05-15 23:30:46 -07:00
typedef enum pf_direction {
pf_dir_in,
pf_dir_out
} pf_direction;
2018-05-28 12:48:37 -07:00
const static char* pfdirstr[] __attribute__ ((unused)) =
{[pf_dir_in] = "in",
[pf_dir_out] = "out"};
typedef struct pf_data_ipv4 {
2018-07-03 13:41:17 -07:00
int ttl;
int tos;
int protocol;
2018-05-28 12:48:37 -07:00
} pf_data_ipv4;
typedef struct pf_data_ipv6 {
2018-07-03 13:41:17 -07:00
int hoplimit;
int protocol;
2018-05-28 12:48:37 -07:00
} pf_data_ipv6;
2018-07-03 13:41:17 -07:00
/*typedef struct ipv4_addr {
u_int32_t addr;
} ipv4_addr;
typedef struct ipv6_addr {
u_int32_t addr1;
u_int32_t addr2;
u_int32_t addr3;
u_int32_t addr4;
} ipv6_addr;*/
typedef struct pf_data_tcp {
int srcport;
int destport;
int length;
} pf_data_tcp;
typedef struct pf_data_udp {
int srcport;
int destport;
int length;
} pf_data_udp;
#define IP_STR_LEN 41 /*40 char ipv6 address + null term*/
2018-05-28 12:48:37 -07:00
2018-05-25 17:12:09 -07:00
typedef struct pf_data {
2018-05-15 23:30:46 -07:00
int rulenum;
char iface[IFACE_LEN];
pf_hit_reason reason;
pf_hit_action action;
pf_direction direction;
int ipversion;
2018-05-28 12:48:37 -07:00
union {
pf_data_ipv4 ipv4_data;
pf_data_ipv6 ipv6_data;
};
2018-07-03 13:41:17 -07:00
/*union {
ipv4_addr ipv4_src;
ipv6_addr ipv6_src;
};
union {
ipv4_addr ipv4_dest;
ipv6_addr ipv6_dest;
};*/
int packet_length;
char src_addr[IP_STR_LEN];
char dest_addr[IP_STR_LEN];
union {
pf_data_tcp tcp_data;
pf_data_udp udp_data;
};
2018-05-25 17:12:09 -07:00
} pf_data;
2018-05-15 23:30:46 -07:00
2018-05-28 12:48:37 -07:00
int pfdata_parse(char* message, pf_data* result);
2018-07-03 13:41:17 -07:00
void pfdata_print(pf_data* data);
2018-07-04 17:09:03 -07:00
2018-07-04 17:44:29 -07:00
void add_intfield(json_object* obj, char* name, int value);
void add_strfield(json_object* obj, char* name, char* value);
2018-07-04 17:09:03 -07:00
int pfdata_to_json(pf_data* data, json_object* obj);
2018-07-31 14:16:53 -07:00
void add_doublefield(json_object* obj, char* name, double value);
const char* null_unknown(const char* p);