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