diff options
author | Kozlov Dmitry <dima@server> | 2011-08-23 18:45:45 +0400 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2011-08-23 18:45:45 +0400 |
commit | 18909197b31b66b5a1445c6f070a3c9fa9ab0501 (patch) | |
tree | 2623220a6eda7e7c9f3735a9162a64a518ff50be /accel-pppd | |
parent | 9bc3fa4216fb2ad043232584b5a5e134e64830ed (diff) | |
download | accel-ppp-18909197b31b66b5a1445c6f070a3c9fa9ab0501.tar.gz accel-ppp-18909197b31b66b5a1445c6f070a3c9fa9ab0501.zip |
ppp: rearranged interface startup procedure
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/ppp/ipcp_opt_ipaddr.c | 41 | ||||
-rw-r--r-- | accel-pppd/ppp/ipv6cp_opt_intfid.c | 4 | ||||
-rw-r--r-- | accel-pppd/ppp/ppp.c | 45 |
3 files changed, 55 insertions, 35 deletions
diff --git a/accel-pppd/ppp/ipcp_opt_ipaddr.c b/accel-pppd/ppp/ipcp_opt_ipaddr.c index f3870691..3a3f6db6 100644 --- a/accel-pppd/ppp/ipcp_opt_ipaddr.c +++ b/accel-pppd/ppp/ipcp_opt_ipaddr.c @@ -127,63 +127,39 @@ static int ipaddr_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o { struct ipaddr_option_t *ipaddr_opt = container_of(opt, typeof(*ipaddr_opt), opt); struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t *)ptr; + struct ifreq ifr; + struct sockaddr_in addr; if (opt32->hdr.len != 6) return IPCP_OPT_REJ; if (ipcp->ppp->ipv4->peer_addr == opt32->val) { ipcp->delay_ack = ccp_ipcp_started(ipcp->ppp); - return IPCP_OPT_ACK; + goto ack; } return IPCP_OPT_NAK; -} -static void if_up(struct ppp_t *ppp) -{ - struct ifreq ifr; - struct sockaddr_in addr; - struct npioctl np; - +ack: memset(&ifr, 0, sizeof(ifr)); memset(&addr, 0, sizeof(addr)); - strcpy(ifr.ifr_name, ppp->ifname); + strcpy(ifr.ifr_name, ipcp->ppp->ifname); addr.sin_family = AF_INET; - addr.sin_addr.s_addr = ppp->ipv4->addr; + addr.sin_addr.s_addr = ipcp->ppp->ipv4->addr; memcpy(&ifr.ifr_addr,&addr,sizeof(addr)); if (ioctl(sock_fd, SIOCSIFADDR, &ifr)) log_ppp_error("ipcp: failed to set PA address: %s\n", strerror(errno)); - addr.sin_addr.s_addr = ppp->ipv4->peer_addr; + addr.sin_addr.s_addr = ipcp->ppp->ipv4->peer_addr; memcpy(&ifr.ifr_dstaddr,&addr,sizeof(addr)); if (ioctl(sock_fd, SIOCSIFDSTADDR, &ifr)) log_ppp_error("ipcp: failed to set remote PA address: %s\n", strerror(errno)); - - triton_event_fire(EV_PPP_ACCT_START, ppp); - if (ppp->stop_time) - return; - - triton_event_fire(EV_PPP_PRE_UP, ppp); - if (ppp->stop_time) - return; - - if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr)) - log_ppp_error("ipcp: failed to get interface flags: %s\n", strerror(errno)); - - ifr.ifr_flags |= IFF_UP | IFF_POINTOPOINT; - - if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr)) - log_ppp_error("ipcp: failed to set interface flags: %s\n", strerror(errno)); - - np.protocol = PPP_IP; - np.mode = NPMODE_PASS; - if (ioctl(ppp->unit_fd, PPPIOCSNPMODE, &np)) - log_ppp_error("ipcp: failed to set NP mode: %s\n", strerror(errno)); + return IPCP_OPT_ACK; } static void ipaddr_print(void (*print)(const char *fmt,...),struct ipcp_option_t *opt, uint8_t *ptr) @@ -214,7 +190,6 @@ static void ipaddr_opt_init() ipcp_option_register(&ipaddr_opt_hnd); load_config(); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); - triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)if_up); } DEFINE_INIT(4, ipaddr_opt_init); diff --git a/accel-pppd/ppp/ipv6cp_opt_intfid.c b/accel-pppd/ppp/ipv6cp_opt_intfid.c index 9a9b9e37..abf124a3 100644 --- a/accel-pppd/ppp/ipv6cp_opt_intfid.c +++ b/accel-pppd/ppp/ipv6cp_opt_intfid.c @@ -160,8 +160,10 @@ static int ipaddr_recv_conf_req(struct ppp_ipv6cp_t *ipv6cp, struct ipv6cp_optio if (opt64->hdr.len != 10) return IPV6CP_OPT_REJ; - if (ipv6cp->ppp->ipv6->intf_id == opt64->val) + if (ipv6cp->ppp->ipv6->intf_id == opt64->val) { + //ipv6cp->delay_ack = ccp_ipcp_started(ipcp->ppp); goto ack; + } return IPV6CP_OPT_NAK; diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c index 7406bf7d..875dbc39 100644 --- a/accel-pppd/ppp/ppp.c +++ b/accel-pppd/ppp/ppp.c @@ -388,6 +388,49 @@ void ppp_recv_proto_rej(struct ppp_t *ppp, uint16_t proto) } } +static void ppp_ifup(struct ppp_t *ppp) +{ + struct ifreq ifr; + struct npioctl np; + + triton_event_fire(EV_PPP_ACCT_START, ppp); + if (ppp->stop_time) + return; + + triton_event_fire(EV_PPP_PRE_UP, ppp); + if (ppp->stop_time) + return; + + memset(&ifr, 0, sizeof(ifr)); + strcpy(ifr.ifr_name, ppp->ifname); + + if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr)) + log_ppp_error("ppp: failed to get interface flags: %s\n", strerror(errno)); + + ifr.ifr_flags |= IFF_UP | IFF_POINTOPOINT; + + if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr)) + log_ppp_error("ppp: failed to set interface flags: %s\n", strerror(errno)); + + if (ppp->ipv4) { + np.protocol = PPP_IP; + np.mode = NPMODE_PASS; + + if (ioctl(ppp->unit_fd, PPPIOCSNPMODE, &np)) + log_ppp_error("ppp: failed to set NP (IPv4) mode: %s\n", strerror(errno)); + } + + if (ppp->ipv6) { + np.protocol = PPP_IPV6; + np.mode = NPMODE_PASS; + + if (ioctl(ppp->unit_fd, PPPIOCSNPMODE, &np)) + log_ppp_error("ppp: failed to set NP (IPv6) mode: %s\n", strerror(errno)); + } + + triton_event_fire(EV_PPP_STARTED, ppp); +} + void __export ppp_layer_started(struct ppp_t *ppp, struct ppp_layer_data_t *d) { struct layer_node_t *n = d->node; @@ -405,7 +448,7 @@ void __export ppp_layer_started(struct ppp_t *ppp, struct ppp_layer_data_t *d) __sync_sub_and_fetch(&ppp_stat.starting, 1); __sync_add_and_fetch(&ppp_stat.active, 1); ppp->ctrl->started(ppp); - triton_event_fire(EV_PPP_STARTED, ppp); + ppp_ifup(ppp); } else { n = list_entry(n->entry.next, typeof(*n), entry); list_for_each_entry(d, &n->items, entry) { |