1 /* $Id: upnpredirect.h,v 1.36 2018/01/16 00:50:49 nanard Exp $ */ 2 /* vim: tabstop=4 shiftwidth=4 noexpandtab 3 * MiniUPnP project 4 * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/ 5 * (c) 2006-2018 Thomas Bernard 6 * This software is subject to the conditions detailed 7 * in the LICENCE file provided within the distribution */ 8 9 #ifndef UPNPREDIRECT_H_INCLUDED 10 #define UPNPREDIRECT_H_INCLUDED 11 12 /* for u_int64_t */ 13 #include <sys/types.h> 14 15 #include "config.h" 16 17 #ifdef ENABLE_LEASEFILE 18 int reload_from_lease_file(void); 19 #ifdef LEASEFILE_USE_REMAINING_TIME 20 void lease_file_rewrite(void); 21 #endif 22 #endif 23 24 /* upnp_redirect() 25 * calls OS/fw dependent implementation of the redirection. 26 * protocol should be the string "TCP" or "UDP" 27 * returns: 0 on success 28 * -1 failed to redirect 29 * -2 already redirected 30 * -3 permission check failed 31 */ 32 int 33 upnp_redirect(const char * rhost, unsigned short eport, 34 const char * iaddr, unsigned short iport, 35 const char * protocol, const char * desc, 36 unsigned int leaseduration); 37 38 /* upnp_redirect_internal() 39 * same as upnp_redirect() without any check */ 40 int 41 upnp_redirect_internal(const char * rhost, unsigned short eport, 42 const char * iaddr, unsigned short iport, 43 int proto, const char * desc, 44 unsigned int timestamp); 45 46 /* upnp_get_redirection_infos() 47 * returns : 0 on success 48 * -1 failed to get the port mapping entry or no entry exists */ 49 int 50 upnp_get_redirection_infos(unsigned short eport, const char * protocol, 51 unsigned short * iport, char * iaddr, int iaddrlen, 52 char * desc, int desclen, 53 char * rhost, int rhostlen, 54 unsigned int * leaseduration); 55 56 /* upnp_get_redirection_infos_by_index() 57 * returns : 0 on success 58 * -1 failed to get the port mapping or index out of range */ 59 int 60 upnp_get_redirection_infos_by_index(int index, 61 unsigned short * eport, char * protocol, 62 unsigned short * iport, 63 char * iaddr, int iaddrlen, 64 char * desc, int desclen, 65 char * rhost, int rhostlen, 66 unsigned int * leaseduration); 67 68 /* upnp_delete_redirection() 69 * returns: 0 on success 70 * -1 on failure*/ 71 int 72 upnp_delete_redirection(unsigned short eport, const char * protocol); 73 74 /* _upnp_delete_redir() 75 * same as above */ 76 int 77 _upnp_delete_redir(unsigned short eport, int proto); 78 79 /* Periodic cleanup functions 80 */ 81 struct rule_state 82 { 83 u_int64_t packets; 84 u_int64_t bytes; 85 struct rule_state * next; 86 unsigned short eport; 87 unsigned char proto; 88 unsigned char to_remove; 89 }; 90 91 /* return a linked list of all rules 92 * or an empty list if there are not enough 93 * As a "side effect", delete rules which are expired */ 94 struct rule_state * 95 get_upnp_rules_state_list(int max_rules_number_target); 96 97 /* return the number of port mapping entries */ 98 int 99 upnp_get_portmapping_number_of_entries(void); 100 101 /* remove_unused_rules() : 102 * also free the list */ 103 void 104 remove_unused_rules(struct rule_state * list); 105 106 /* upnp_get_portmappings_in_range() 107 * return a list of all "external" ports for which a port 108 * mapping exists */ 109 unsigned short * 110 upnp_get_portmappings_in_range(unsigned short startport, 111 unsigned short endport, 112 const char * protocol, 113 unsigned int * number); 114 115 /* stuff for responding to miniupnpdctl */ 116 #ifdef USE_MINIUPNPDCTL 117 void 118 write_ruleset_details(int s); 119 #endif 120 121 #endif 122 123 124