/* called from natpmp.c too */ int _upnp_delete_redir(unsigned short eport, int proto) { int r; #if defined(__linux__) r = delete_redirect_and_filter_rules(eport, proto); #elif defined(USE_PF) r = delete_redirect_and_filter_rules(ext_if_name, eport, proto); #else r = delete_redirect_rule(ext_if_name, eport, proto); delete_filter_rule(ext_if_name, eport, proto); #endif #ifdef ENABLE_LEASEFILE lease_file_remove( eport, proto); #endif #ifdef ENABLE_EVENTS upnp_event_var_change_notify(EWanIPC); #endif return r; }
int main(int argc, char ** argv) { unsigned short eport, iport; const char * iaddr; printf("Usage %s <ext_port> <internal_ip> <internal_port>\n", argv[0]); if(argc<4) return -1; openlog("testiptcrdr", LOG_PERROR|LOG_CONS, LOG_LOCAL0); eport = (unsigned short)atoi(argv[1]); iaddr = argv[2]; iport = (unsigned short)atoi(argv[3]); printf("trying to redirect port %hu to %s:%hu\n", eport, iaddr, iport); if(addnatrule(IPPROTO_TCP, eport, iaddr, iport, NULL) < 0) return -1; if(add_filter_rule(IPPROTO_TCP, NULL, iaddr, iport) < 0) return -1; /* test */ { unsigned short p1, p2; char addr[16]; int proto2; char desc[256]; char rhost[256]; unsigned int timestamp; u_int64_t packets, bytes; desc[0] = '\0'; if(get_redirect_rule_by_index(0, "", &p1, addr, sizeof(addr), &p2, &proto2, desc, sizeof(desc), rhost, sizeof(rhost), ×tamp, &packets, &bytes) < 0) { printf("rule not found\n"); } else { printf("redirected port %hu to %s:%hu proto %d packets=%" PRIu64 " bytes=%" PRIu64 "\n", p1, addr, p2, proto2, packets, bytes); } } printf("trying to list nat rules :\n"); list_redirect_rule(argv[1]); printf("deleting\n"); delete_redirect_and_filter_rules(eport, IPPROTO_TCP); return 0; }
/* called from natpmp.c too */ int _upnp_delete_redir(unsigned short eport, int proto) { int r; #ifdef MBB_FEATURE_PCP int wan_status; PARA_TO_PCP_PROC_ST pcp_para; #endif #ifdef MBB_FEATURE_PCP wan_status = MgntGetWanState(); if (WAN_STATUS_CONNECTED == wan_status) { memset(&pcp_para, 0, sizeof(pcp_para)); //eport是pcp的iport fill_pcp_process_para(&pcp_para, 0, NULL, eport, proto, 0, 0, NULL); send_msg_to_pcp_client(ATP_MSG_PCP_DELETE_PORTMAP, &pcp_para); } #endif #if defined(__linux__) NP_UPNP_INFO("enter _upnp_delete_redir()\n"); NP_UPNP_DEBUG("defined(__linux__), call delete_redirect_and_filter_rules()\n"); r = delete_redirect_and_filter_rules(eport, proto); #else r = delete_redirect_rule(ext_if_name, eport, proto); delete_filter_rule(ext_if_name, eport, proto); #endif #ifdef ENABLE_LEASEFILE lease_file_remove( eport, proto); #endif #ifdef ENABLE_EVENTS upnp_event_var_change_notify(EWanIPC); #endif return r; }