/* bind for PPP */ static int pppoe_session_bind_ppp(pppoe_session *_this) { int len; npppd_ppp *ppp; struct sockaddr_dl sdl; ppp = NULL; if ((ppp = ppp_create()) == NULL) goto fail; PPPOE_SESSION_ASSERT(_this->ppp == NULL); if (_this->ppp != NULL) return -1; _this->ppp = ppp; ppp->tunnel_type = PPP_TUNNEL_PPPOE; ppp->phy_context = _this; ppp->send_packet = pppoe_session_ppp_output; ppp->phy_close = pppoe_session_close_by_ppp; strlcpy(ppp->phy_label, PPPOE_SESSION_LISTENER_LABEL(_this), sizeof(ppp->phy_label)); memset(&sdl, 0, sizeof(sdl)); sdl.sdl_len = sizeof(sdl); sdl.sdl_family = AF_LINK; len = strlen(pppoe_session_listen_ifname(_this)); memcpy(sdl.sdl_data, pppoe_session_listen_ifname(_this), len); sdl.sdl_nlen = len; sdl.sdl_alen = ETHER_ADDR_LEN; memcpy(sdl.sdl_data + len, _this->ether_addr, ETHER_ADDR_LEN); memcpy(&ppp->phy_info.peer_dl, &sdl, sizeof(sdl)); if (ppp_init(npppd_get_npppd(), ppp) != 0) goto fail; ppp->has_acf = 0; pppoe_session_log(_this, LOG_NOTICE, "logtype=PPPBind ppp=%d", ppp->id); ppp_start(ppp); return 0; fail: pppoe_session_log(_this, LOG_ERR, "failed binding ppp"); if (ppp != NULL) ppp_destroy(ppp); _this->ppp = NULL; return 1; }
/* bind() for ppp */ static int pptp_call_bind_ppp(pptp_call *_this) { npppd_ppp *ppp; ppp = NULL; if ((ppp = ppp_create()) == NULL) goto fail; PPTP_CALL_ASSERT(_this->ppp == NULL); if (_this->ppp != NULL) return -1; _this->ppp = ppp; ppp->phy_context = _this; ppp->tunnel_type = NPPPD_TUNNEL_PPTP; ppp->send_packet = pptp_call_ppp_output; ppp->phy_close = pptp_call_closed_by_ppp; strlcpy(ppp->phy_label, PPTP_CTRL_LISTENER_TUN_NAME(_this->ctrl), sizeof(ppp->phy_label)); PPTP_CALL_ASSERT(sizeof(ppp->phy_info) >= _this->ctrl->peer.ss_len); memcpy(&ppp->phy_info, &_this->ctrl->peer, MIN(sizeof(ppp->phy_info), _this->ctrl->peer.ss_len)); if (ppp_init(npppd_get_npppd(), ppp) != 0) goto fail; pptp_call_log(_this, LOG_NOTICE, "logtype=PPPBind ppp=%d", ppp->id); ppp_start(ppp); return 0; fail: pptp_call_log(_this, LOG_ERR, "failed binding ppp"); if (ppp != NULL) ppp_destroy(ppp); _this->ppp = NULL; return 1; }
/* bind ppp */ static int l2tp_call_bind_ppp(l2tp_call *_this, dialin_proxy_info *dpi) { int code, errcode; npppd_ppp *ppp; code = L2TP_CDN_RCODE_BUSY; errcode = 0; ppp = NULL; if ((ppp = ppp_create()) == NULL) goto fail; ASSERT(_this->ppp == NULL); if (_this->ppp != NULL) return -1; _this->ppp = ppp; ppp->tunnel_type = NPPPD_TUNNEL_L2TP; ppp->phy_context = _this; ppp->send_packet = l2tp_call_ppp_output; ppp->phy_close = l2tp_call_closed_by_ppp; strlcpy(ppp->phy_label, L2TP_CTRL_LISTENER_TUN_NAME(_this->ctrl), sizeof(ppp->phy_label)); L2TP_CALL_ASSERT(sizeof(ppp->phy_info) >= _this->ctrl->peer.ss_len); memcpy(&ppp->phy_info, &_this->ctrl->peer, MIN(sizeof(ppp->phy_info), _this->ctrl->peer.ss_len)); strlcpy(ppp->calling_number, _this->calling_number, sizeof(ppp->calling_number)); if (ppp_init(npppd_get_npppd(), ppp) != 0) { l2tp_call_log(_this, LOG_ERR, "failed binding ppp"); goto fail; } l2tp_call_log(_this, LOG_NOTICE, "logtype=PPPBind ppp=%d", ppp->id); if (DIALIN_PROXY_IS_REQUESTED(dpi)) { if (!L2TP_CTRL_CONF(_this->ctrl)->accept_dialin) { l2tp_call_log(_this, LOG_ERR, "'accept_dialin' is 'false' in the setting."); code = L2TP_CDN_RCODE_ERROR_CODE; errcode = L2TP_ECODE_INVALID_MESSAGE; goto fail; } if (ppp_dialin_proxy_prepare(ppp, dpi) != 0) { code = L2TP_CDN_RCODE_TEMP_NOT_AVALIABLE; goto fail; } } ppp_start(ppp); return 0; fail: if (ppp != NULL) ppp_destroy(ppp); _this->ppp = NULL; l2tp_call_disconnect(_this, code, 0, NULL, NULL, 0); return 1; }
static void ppp_stop0(npppd_ppp *_this) { char mppe_str[BUFSIZ]; char label[512]; #ifdef USE_NPPPD_RADIUS ppp_set_radius_terminate_cause(_this, RADIUS_TERMNATE_CAUSE_NAS_ERROR); #endif ppp_set_disconnect_cause(_this, PPP_DISCON_NORMAL, 0, 1 /* by local */, NULL); _this->end_monotime = get_monosec(); if (_this->phy_close != NULL) _this->phy_close(_this); _this->phy_close = NULL; /* * NAT/Blackhole detection for PPTP(GRE) */ if (_this->lcp.dialin_proxy != 0 && _this->lcp.dialin_proxy_lcp_renegotiation == 0) { /* No LCP packets on dialin proxy without LCP renegotiation */ } else if (_this->lcp.recv_ress == 0) { /* No responses */ if (_this->lcp.recv_reqs == 0) /* No requests */ ppp_log(_this, LOG_WARNING, "no PPP frames from the " "peer. router/NAT issue? (may have filtered out)"); else ppp_log(_this, LOG_WARNING, "my PPP frames may not " "have arrived at the peer. router/NAT issue? (may " "be the only-first-person problem)"); } #ifdef USE_NPPPD_PIPEX if (npppd_ppp_pipex_disable(_this->pppd, _this) != 0) ppp_log(_this, LOG_ERR, "npppd_ppp_pipex_disable() failed: %m"); #endif ppp_set_tunnel_label(_this, label, sizeof(label)); #ifdef USE_NPPPD_MPPE if (_this->mppe_started) { snprintf(mppe_str, sizeof(mppe_str), "mppe=yes mppe_in=%dbits,%s mppe_out=%dbits,%s", _this->mppe.recv.keybits, (_this->mppe.recv.stateless)? "stateless" : "stateful", _this->mppe.send.keybits, (_this->mppe.send.stateless)? "stateless" : "stateful"); } else #endif snprintf(mppe_str, sizeof(mppe_str), "mppe=no"); ppp_log(_this, LOG_NOTICE, "logtype=TUNNELUSAGE user=\"%s\" duration=%ldsec layer2=%s " "layer2from=%s auth=%s data_in=%llubytes,%upackets " "data_out=%llubytes,%upackets error_in=%u error_out=%u %s " "iface=%s", _this->username[0]? _this->username : "******", (long)(_this->end_monotime - _this->start_monotime), _this->phy_label, label, _this->username[0]? ppp_peer_auth_string(_this) : "none", (unsigned long long)_this->ibytes, _this->ipackets, (unsigned long long)_this->obytes, _this->opackets, _this->ierrors, _this->oerrors, mppe_str, npppd_ppp_get_iface_name(_this->pppd, _this)); #ifdef USE_NPPPD_RADIUS npppd_ppp_radius_acct_stop(_this->pppd, _this); #endif npppd_ppp_unbind_iface(_this->pppd, _this); #ifdef USE_NPPPD_MPPE mppe_fini(&_this->mppe); #endif evtimer_del(&_this->idle_event); npppd_release_ip(_this->pppd, _this); ppp_destroy(_this); }