/* use W Richard Stevens' SO_LINGER trick to elicit a TCP RST */ static int serve_reset(ne_socket *sock, void *ud) { minisleep(); reset_socket(sock); exit(0); return 0; }
/* ANT_CHANNEL_SOCKET::BLOCK_READ() -------------------------------- */ char *ANT_channel_socket::block_read(char *into, long long length) { char *answer; do if ((answer = socket->block_read(into, length)) == NULL) reset_socket(); while (answer == NULL); return answer; }
/* ANT_CHANNEL_SOCKET::BLOCK_WRITE() --------------------------------- returns the number of bytes written or -ve on errror */ long long ANT_channel_socket::block_write(char *data, long long length) { long long answer; do if ((answer = socket->block_write(data, length)) < length) reset_socket(); while (answer < length); return answer; }
/* ANT_CHANNEL_SOCKET::GETSZ() --------------------------- */ char *ANT_channel_socket::getsz(char terminator) { char *answer; do if ((answer = socket->getsz(terminator)) == NULL) reset_socket(); while (answer == NULL); return answer; }
void Client::connect() { reset_socket(); // [!]IRainman moved to two function: // void Client::on(Failed, const string& aLine) // void Client::disconnect(bool graceLess) clearAvailableBytes(); setAutoReconnect(true); setReconnDelay(120 + Util::rand(0, 60)); const FavoriteHubEntry* fhe = reloadSettings(true); // [!]IRainman fix. resetRegistered(); // [!] resetOp(); // [+] // [-] setMyIdentity(Identity(ClientManager::getInstance()->getMe(), 0)); [-] // [-] setHubIdentity(Identity()); [-] // [~] IRainman fix. state = STATE_CONNECTING; try { #ifdef FLYLINKDC_USE_CS_CLIENT_SOCKET FastLock lock(csSock); // [+] brain-ripper #endif m_client_sock = BufferedSocket::getBufferedSocket(m_separator); m_client_sock->addListener(this); m_client_sock->connect(m_address, m_port, m_secure, BOOLSETTING(ALLOW_UNTRUSTED_HUBS), true); dcdebug("Client::connect() %p\n", (void*)this); } catch (const Exception& e) { state = STATE_DISCONNECTED; fire(ClientListener::Failed(), this, e.getError()); } m_isActivMode = ClientManager::isActive(fhe); // [+] IRainman opt. updateActivity(); }
void Client::shutdown() { TimerManager::getInstance()->removeListener(this); // [+] IRainman fix. state = STATE_DISCONNECTED;//[!] IRainman fix // [+] brain-ripper // Ugly hack to avoid deadlock: // this function captures csSock section // and inside putSocket there is call to removeListeners // that wants to capture listener's critical section. // that section may be captured in another thread (function Client::on(Failed, ...)) // and that function wait on csSock section. // // So remove listeners in advance. // It is quite unsafe, since there is no critical section on socket // but shutdown called from single thread... // Hope this helps // [-] IRainman fix: please see reset_socket(). // [-] if (sock) // [-] sock->removeListeners(); // [~] reset_socket(); }
void process_new_gateway ( lisp_addr_t gateway, lispd_iface_elt *iface ) { lisp_addr_t **gw_addr = NULL; int afi = AF_UNSPEC; lispd_mapping_list *map_list = NULL; switch(gateway.afi){ case AF_INET: gw_addr = &(iface->ipv4_gateway); afi = AF_INET; iface->ipv4_changed = TRUE; break; case AF_INET6: gw_addr = &(iface->ipv6_gateway); afi = AF_INET6; iface->ipv6_changed = TRUE; break; default: return; } if (*gw_addr == NULL){ // The default gateway of this interface is not deffined yet *gw_addr = clone_lisp_addr(&gateway); if (*gw_addr == NULL){ free (*gw_addr); *gw_addr = NULL; return; } }else{ copy_lisp_addr(*gw_addr,&gateway); } #ifndef VPNAPI add_route(afi,iface->iface_index,NULL,NULL,*gw_addr,0,100,iface->iface_index); #endif #ifdef VPNAPI if (iface->status != UP){ lispd_log_msg(LISP_LOG_DEBUG_1,"process_new_gateway: Probably the interface %s is UP " "but we didn't receive netlink indicating this. Change %s status to UP", iface->iface_name,iface->iface_name); iface->status = UP; /* * If we don't have default control or output iface, recalculate it */ if ((default_ctrl_iface_v4 == NULL && iface->ipv4_address->afi != AF_UNSPEC) || (default_ctrl_iface_v6 == NULL && iface->ipv6_address->afi != AF_UNSPEC)){ lispd_log_msg(LISP_LOG_DEBUG_2,"process_new_gateway: Recalculate new control interface"); set_default_ctrl_ifaces(); } if ((default_out_iface_v4 == NULL && iface->ipv4_address->afi != AF_UNSPEC) || (default_out_iface_v6 == NULL && iface->ipv6_address->afi != AF_UNSPEC)){ lispd_log_msg(LISP_LOG_DEBUG_2,"process_new_gateway: Recalculate new data interface"); set_default_output_ifaces(); } } if (gateway.afi == AF_INET){ reset_socket(ipv4_data_input_fd); reset_socket(ipv4_control_input_fd); }else{ reset_socket(ipv6_data_input_fd); reset_socket(ipv6_control_input_fd); } #endif /* Check if the interface is behind NAT */ if(nat_aware==TRUE){ if (iface->status == UP && iface->ipv4_address != NULL){ map_list = get_mappings_from_iface(iface); restart_info_request_process(map_list,iface->ipv4_address); free_mapping_list(map_list,FALSE); } } /* Reprograming SMR timer*/ if (smr_timer == NULL){ smr_timer = create_timer (SMR_TIMER); } start_timer(smr_timer, LISPD_SMR_TIMEOUT,(timer_callback)init_smr, NULL); }