This repository has been archived by the owner on Jan 21, 2019. It is now read-only.
/
rule.h
118 lines (95 loc) · 2.96 KB
/
rule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <linux/netfilter.h>
#include <libipq/libipq.h>
#include <stdio.h>
#include <stdlib.h>
#include <libnet.h>
#include "common.h"
#include "caract.h"
#ifndef RULE_H
#define RULE_H
//defini les verdicts
#define TO_ACCEPT 1
#define TO_DROP 2
#define MATCHED 3
#define NOT_MATCHED 4
typedef struct icmp_rule{
u8 is_type_used;//si on utilise le champ
u8 type;
} icmp_rule_t;
typedef struct udp_rule{
u8 is_port_src_used;
u8 is_port_dst_used;
u16 port_src_beg;
u16 port_src_end;
u16 port_dst_beg;
u16 port_dst_end;
} udp_rule_t;
typedef struct tcp_rule{
u8 is_port_src_used;
u8 is_port_dst_used;
u16 port_src_beg;
u16 port_src_end;
u16 port_dst_beg;
u16 port_dst_end;
u8 is_flags_used;
u8 flags;
} tcp_rule_t;
typedef union rule_next_layer{
icmp_rule_t icmp_rule;
udp_rule_t udp_rule;
tcp_rule_t tcp_rule;
} rule_next_layer_t;
typedef struct rule{
u16 verdict;
u32 id;
u8 is_indev_used;
u8 is_outdev_used;
u8 is_commande_used;
u8 is_addr_src_used;
u8 is_addr_dst_used;
u8 is_proto_used;
u8 indev[8];
u8 outdev[8];
u8 commande[8];
u32 addr_src_beg;
u32 addr_src_end;
u32 addr_dst_beg;
u32 addr_dst_end;
u16 proto;
rule_next_layer_t next_layer;
} rule_t;
/*********** Creation ******************/
//Fonctions de base de rule
//fonction qui cree une rule vide
rule_t create_void_rule();
rule_t copy_rule(rule_t r);
rule_t fill_verdict_rule(rule_t r, u16 v);
rule_t fill_indev_rule(rule_t r,u8 * indev);
rule_t fill_outdev_rule(rule_t r,u8 * outdev);
rule_t fill_commande_rule(rule_t r,u8 * commande);
rule_t fill_addr_src_rule(rule_t r,u32 addr_src_beg,u32 addr_src_end);
rule_t fill_addr_dst_rule(rule_t r,u32 addr_dst_beg,u32 addr_dst_end);
//remplir la derniere partie, rempli un icmp/tcp/udp dans un
//transp_layer puis rempli le proto et is_proto_used
rule_t add_icmp_rule(rule_t r,icmp_rule_t icmpr);
rule_t add_udp_rule(rule_t r,udp_rule_t udpr);
rule_t add_tcp_rule(rule_t r,tcp_rule_t tcpr);
//creer des regles vides
icmp_rule_t create_void_icmp_rule();
udp_rule_t create_void_udp_rule();
tcp_rule_t create_void_tcp_rule();
//necessite un icmp_rule vide qui sera reecrase, peut mieux faire...
icmp_rule_t fill_icmp_type_rule(icmp_rule_t r,u8 type);
udp_rule_t fill_udp_port_src_rule(udp_rule_t r,u32 port_src_beg,u32 port_src_end);
udp_rule_t fill_udp_port_dst_rule(udp_rule_t r,u32 port_dst_beg,u32 port_dst_end);
tcp_rule_t fill_tcp_port_src_rule(tcp_rule_t r,u32 port_src_beg,u32 port_src_end);
tcp_rule_t fill_tcp_port_dst_rule(tcp_rule_t r,u32 port_dst_beg,u32 port_dst_end);
tcp_rule_t fill_tcp_flags_rules(tcp_rule_t r,u8 flags);
/********************* Verification ****************/
//verifie si un caract est coherent avec une regle
u16 is_matched(caract_t c,rule_t r);
u16 is_next_layer_matched(u16 proto,caract_next_layer_t tlc,rule_next_layer_t tlr);
u16 is_icmp_matched(icmp_caract_t ic,icmp_rule_t ir);
u16 is_udp_matched(udp_caract_t uc,udp_rule_t ur);
u16 is_tcp_matched(tcp_caract_t tc,tcp_rule_t tr);
#endif