1 /* $Id: commonrdr.h,v 1.11 2019/10/02 22:12:02 nanard Exp $ */
2 /* MiniUPnP project
3  * (c) 2006-2020 Thomas Bernard
4  * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
5  * This software is subject to the conditions detailed
6  * in the LICENCE file provided within the distribution */
7 #ifndef COMMONRDR_H_INCLUDED
8 #define COMMONRDR_H_INCLUDED
9 
10 #include "config.h"
11 
12 /* init and shutdown functions */
13 /* init_redirect() return values :
14  *  0 : OK
15  * -1 : error */
16 int
17 init_redirect(void);
18 
19 void
20 shutdown_redirect(void);
21 
22 /* get_redirect_rule_count()
23  * return value : -1 for error or the number of redirection rules */
24 int
25 get_redirect_rule_count(const char * ifname);
26 
27 /* get_redirect_rule() gets internal IP and port from
28  * interface, external port and protocol
29  * return value :
30  *  0 success (rule found)
31  * -1 error or rule not found
32  */
33 int
34 get_redirect_rule(const char * ifname, unsigned short eport, int proto,
35                   char * iaddr, int iaddrlen, unsigned short * iport,
36                   char * desc, int desclen,
37                   char * rhost, int rhostlen,
38                   unsigned int * timestamp,
39                   u_int64_t * packets, u_int64_t * bytes);
40 
41 /* get_redirect_rule_by_index()
42  * return values :
43  *  0 success (rule found)
44  * -1 error or rule not found */
45 int
46 get_redirect_rule_by_index(int index,
47                            char * ifname, unsigned short * eport,
48                            char * iaddr, int iaddrlen, unsigned short * iport,
49                            int * proto, char * desc, int desclen,
50                            char * rhost, int rhostlen,
51                            unsigned int * timestamp,
52                            u_int64_t * packets, u_int64_t * bytes);
53 
54 /* return an (malloc'ed) array of "external" port for which there is
55  * a port mapping. number is the size of the array */
56 unsigned short *
57 get_portmappings_in_range(unsigned short startport, unsigned short endport,
58                           int proto, unsigned int * number);
59 
60 /* update the port mapping internal port, description and timestamp */
61 int
62 update_portmapping(const char * ifname, unsigned short eport, int proto,
63                    unsigned short iport, const char * desc,
64                    unsigned int timestamp);
65 
66 /* update the port mapping description and timestamp */
67 int
68 update_portmapping_desc_timestamp(const char * ifname,
69                    unsigned short eport, int proto,
70                    const char * desc, unsigned int timestamp);
71 
72 #if defined(USE_NETFILTER)
73 /*
74  * only provided by nftables implementation at the moment.
75  * Should be implemented for iptables too, for consistency
76  */
77 
78 typedef enum {
79 	RDR_TABLE_NAME,
80 	RDR_NAT_PREROUTING_CHAIN_NAME,
81 	RDR_NAT_POSTROUTING_CHAIN_NAME,
82 	RDR_FORWARD_CHAIN_NAME,
83 } rdr_name_type;
84 
85 /*
86  * used by the config file parsing in the core
87  * to set
88  */
89 
90 int set_rdr_name( rdr_name_type param, const char * string );
91 
92 #endif
93 
94 #endif
95