PF_RING API
API documentation for PF_RING: high-speed packet capture, filtering and analysis framework.
rrc.h
Go to the documentation of this file.
1 /*
2  *
3  * (C) 2017-18 - ntop.org
4  *
5  * http://www.ntop.org/
6  *
7  * This code is proprietary code subject to the terms and conditions
8  * defined in LICENSE file which is part of this source code package.
9  *
10  */
11 
12 #ifndef RRC_LIB
13 #define RRC_LIB
14 
21 //#define DEBUG
22 
23 #include "nbpf.h"
24 
25 #define MAX_NUM_PORTS 10
26 #define MAX_NUM_RULES 0x7FFFFFFF
27 #define MAX_NUM_USER_RULES (MAX_NUM_RULES-2)
28 
29 #define DEFAULT_RULE_ID (MAX_NUM_RULES-2)
30 #define INIT_RULE_ID (MAX_NUM_RULES-1)
31 
32 /*
33  * RRC switch port numbers are 1,2,3,4
34  *
35  * (host)
36  *
37  * 3 4 PEP (internal) ports
38  * ___|_______|___
39  * | |
40  * | |
41  * | RRC |
42  * | Switch |
43  * | |
44  * |___ _______ ___|
45  * | |
46  * 1 2 EPL (external) Ethernet ports
47  *
48  * (network)
49  */
50 
51 #define RRC_INIT_FLAG_PORTMASK (0 << 1) /* Set destination port mask (this is not compatible with redirection rules) */
52 
53 typedef enum {
54  PERMIT = 0, /* EGRESS_TRAFFIC only */
55  DENY, /* INGRESS_TRAFFIC (recommended) or EGRESS_TRAFFIC */
56  REDIRECT /* INGRESS_TRAFFIC only */
57 } rrc_policy_t;
58 
59 typedef enum {
60  EGRESS_TRAFFIC = 0, /* filter traffic leaving the port */
61  INGRESS_TRAFFIC /* steer traffic entering the port to another port */
62 } rrc_filter_type_t;
63 
64 /* backward compatibility */
65 #define EGRESS_TRAFFIC_FILTERING EGRESS_TRAFFIC
66 #define INGRESS_TRAFFIC_STEERING INGRESS_TRAFFIC
67 
68 typedef struct {
69  u_int64_t packets;
70  u_int64_t bytes;
71 } __attribute__((packed))
72 rrc_stats_t;
73 
74 /* NOTE: all the fields of the structs reported here are in network byte order */
75 
76 typedef union {
77  u_int8_t u6_addr8[16];
78  u_int16_t u6_addr16[8];
79  u_int32_t u6_addr32[4];
80 } __attribute__((packed))
81 rrc_in6_addr_t;
82 
83 typedef union {
84  rrc_in6_addr_t v6; /* an IPv6 address */
85  u_int32_t v4; /* an IPv4 address */
86 } __attribute__((packed))
87 rrc_ip_addr_t;
88 
89 typedef struct {
90  rrc_ip_addr_t host; /* The network address part */
91  rrc_ip_addr_t mask; /* The network mask */
92  u_int8_t ip_version; /* the IP address version, 4 or 6 */
93 } __attribute__((packed))
94 rrc_network_t;
95 
96 typedef struct {
97  u_int16_t low; /* the low port number of a port range */
98  u_int16_t high; /* the high port number of a port range, if suported */
99 } __attribute__((packed))
100 rrc_port_range_t;
101 
102 typedef struct {
103  u_int8_t smac[6]; /* source MAC */
104  u_int8_t dmac[6]; /* destination MAC */
105  u_int8_t proto; /* L3 protocol */
106  u_int8_t __padding;
107  u_int16_t vlan_id; /* VLAN id */
108  rrc_network_t shost; /* source host or network, Ipv4 or Ipv6 */
109  rrc_network_t dhost; /* destination host or network, Ipv4 or Ipv6 */
110  rrc_port_range_t sport; /* L3 source port */
111  rrc_port_range_t dport; /* L3 destination port */
112 } __attribute__((packed))
113 rrc_match_t;
114 
115 typedef struct rrc_port rrc_port_t;
116 
122 int rrc_init(u_int32_t flags);
123 
129 rrc_port_t *rrc_port_get(int portNumber);
130 
139 int rrc_add_default_rule(rrc_port_t *port, rrc_filter_type_t type, rrc_policy_t action, int redirectPortNumber);
140 
152 int rrc_add_rule(rrc_port_t *port, int ruleNumber, rrc_filter_type_t type, rrc_match_t *rule, rrc_policy_t action, int redirectPortNumber);
153 
165 int rrc_add_nbpf_rule(rrc_port_t *port, int ruleNumber, rrc_filter_type_t type, nbpf_rule_core_fields_t *nBPFRule, rrc_policy_t action, int redirectPortNumber);
166 
175 int rrc_remove_rule(rrc_port_t *port, int ruleNumber, rrc_filter_type_t type);
176 
183 int rrc_remove_all_rules(rrc_port_t *port, rrc_filter_type_t type);
184 
196 int rrc_read_rule_stats(rrc_port_t *port, int ruleNumber, rrc_filter_type_t type, rrc_stats_t *stats);
197 
204 int rrc_read_port_stats(rrc_port_t *port, rrc_stats_t *stats);
205 
210 int rrc_port_apply(rrc_port_t *port, rrc_filter_type_t type);
211 
216 int rrc_apply();
217 
227 int rrc_add_mirror(rrc_port_t *in_port, rrc_port_t *out_port, rrc_match_t *rule);
228 
233 int rrc_remove_mirror(rrc_port_t *out_port);
234 
242 int rrc_set_load_balancer(rrc_port_t *out_ports, int num_out_ports, rrc_match_t *r);
243 
249 int rrc_ifname_to_phys_port(const char *ifname);
250 
256 int rrc_get_external_phys_port(int internal_phys_port);
257 
263 int rrc_get_internal_phys_port(int external_phys_port);
264 
268 void rrc_dump_rules(rrc_port_t *port, rrc_filter_type_t type);
269 
273 void rrc_set_log_level(u_int8_t l);
274 
278 void rrc_set_log_file(FILE *f);
279 
280 #endif /* RRC_LIB */
281 
void rrc_dump_rules(rrc_port_t *port, rrc_filter_type_t type)
int rrc_read_rule_stats(rrc_port_t *port, int ruleNumber, rrc_filter_type_t type, rrc_stats_t *stats)
int rrc_ifname_to_phys_port(const char *ifname)
void rrc_set_log_file(FILE *f)
void rrc_set_log_level(u_int8_t l)
int rrc_port_apply(rrc_port_t *port, rrc_filter_type_t type)
int rrc_apply()
Definition: pf_ring.h:259
int rrc_add_default_rule(rrc_port_t *port, rrc_filter_type_t type, rrc_policy_t action, int redirectPortNumber)
rrc_port_t * rrc_port_get(int portNumber)
int rrc_set_load_balancer(rrc_port_t *out_ports, int num_out_ports, rrc_match_t *r)
int rrc_remove_mirror(rrc_port_t *out_port)
int rrc_add_rule(rrc_port_t *port, int ruleNumber, rrc_filter_type_t type, rrc_match_t *rule, rrc_policy_t action, int redirectPortNumber)
int rrc_get_external_phys_port(int internal_phys_port)
int rrc_add_nbpf_rule(rrc_port_t *port, int ruleNumber, rrc_filter_type_t type, nbpf_rule_core_fields_t *nBPFRule, rrc_policy_t action, int redirectPortNumber)
int rrc_remove_rule(rrc_port_t *port, int ruleNumber, rrc_filter_type_t type)
int rrc_read_port_stats(rrc_port_t *port, rrc_stats_t *stats)
int rrc_get_internal_phys_port(int external_phys_port)
int rrc_add_mirror(rrc_port_t *in_port, rrc_port_t *out_port, rrc_match_t *rule)
int rrc_init(u_int32_t flags)
int rrc_remove_all_rules(rrc_port_t *port, rrc_filter_type_t type)