diff options
author | Kozlov Dmitry <xeb@mail.ru> | 2012-06-19 19:06:06 +0400 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2012-06-19 19:06:06 +0400 |
commit | 02b3fb2b24aacd90d535c2136a055f529d722974 (patch) | |
tree | 6243dd815869add07be2bad5846e7817b732ac59 /accel-pppd/ipv6 | |
parent | c553a7bbbc96d36ba4d0999bb172c7a926518eb1 (diff) | |
download | accel-ppp-02b3fb2b24aacd90d535c2136a055f529d722974.tar.gz accel-ppp-02b3fb2b24aacd90d535c2136a055f529d722974.zip |
general preparation for IPoE integration
Diffstat (limited to 'accel-pppd/ipv6')
-rw-r--r-- | accel-pppd/ipv6/dhcpv6.c | 88 | ||||
-rw-r--r-- | accel-pppd/ipv6/dhcpv6.h | 2 | ||||
-rw-r--r-- | accel-pppd/ipv6/dhcpv6_packet.c | 2 | ||||
-rw-r--r-- | accel-pppd/ipv6/nd.c | 48 |
4 files changed, 70 insertions, 70 deletions
diff --git a/accel-pppd/ipv6/dhcpv6.c b/accel-pppd/ipv6/dhcpv6.c index ddc977ba..93888245 100644 --- a/accel-pppd/ipv6/dhcpv6.c +++ b/accel-pppd/ipv6/dhcpv6.c @@ -42,7 +42,7 @@ static int conf_dnssl_size; struct dhcpv6_pd { - struct ppp_pd_t pd; + struct ap_private pd; struct dhcpv6_opt_clientid *clientid; uint32_t addr_iaid; uint32_t dp_iaid; @@ -56,22 +56,22 @@ static struct triton_context_t dhcpv6_ctx; static uint8_t *buf; static void *pd_key; -static void ev_ppp_started(struct ppp_t *ppp) +static void ev_ppp_started(struct ap_session *ses) { struct ipv6_mreq mreq; struct dhcpv6_pd *pd; - if (!ppp->ipv6) + if (!ses->ipv6) return; pd = _malloc(sizeof(*pd)); memset(pd, 0, sizeof(*pd)); pd->pd.key = &pd_key; - list_add_tail(&pd->pd.entry, &ppp->pd_list); + list_add_tail(&pd->pd.entry, &ses->pd_list); memset(&mreq, 0, sizeof(mreq)); - mreq.ipv6mr_interface = ppp->ifindex; + mreq.ipv6mr_interface = ses->ifindex; mreq.ipv6mr_multiaddr.s6_addr32[0] = htonl(0xff020000); mreq.ipv6mr_multiaddr.s6_addr32[3] = htonl(0x010002); @@ -81,11 +81,11 @@ static void ev_ppp_started(struct ppp_t *ppp) } } -static struct dhcpv6_pd *find_pd(struct ppp_t *ppp) +static struct dhcpv6_pd *find_pd(struct ap_session *ses) { - struct ppp_pd_t *pd; + struct ap_private *pd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == &pd_key) return container_of(pd, struct dhcpv6_pd, pd); } @@ -93,9 +93,9 @@ static struct dhcpv6_pd *find_pd(struct ppp_t *ppp) return NULL; } -static void ev_ppp_finished(struct ppp_t *ppp) +static void ev_ppp_finished(struct ap_session *ses) { - struct dhcpv6_pd *pd = find_pd(ppp); + struct dhcpv6_pd *pd = find_pd(ses); if (!pd) return; @@ -106,7 +106,7 @@ static void ev_ppp_finished(struct ppp_t *ppp) _free(pd->clientid); if (pd->ipv6_dp) - ipdb_put_ipv6_prefix(ppp, pd->ipv6_dp); + ipdb_put_ipv6_prefix(ses, pd->ipv6_dp); _free(pd); } @@ -119,8 +119,8 @@ static void dhcpv6_send(struct dhcpv6_packet *reply) addr.sin6_family = AF_INET6; addr.sin6_port = htons(DHCPV6_CLIENT_PORT); addr.sin6_addr.s6_addr32[0] = htons(0xfe80); - *(uint64_t *)(addr.sin6_addr.s6_addr + 8) = reply->ppp->ipv6->peer_intf_id; - addr.sin6_scope_id = reply->ppp->ifindex; + *(uint64_t *)(addr.sin6_addr.s6_addr + 8) = reply->ses->ipv6->peer_intf_id; + addr.sin6_scope_id = reply->ses->ifindex; sendto(dhcpv6_hnd.fd, reply->hdr, reply->endptr - (void *)reply->hdr, 0, (struct sockaddr *)&addr, sizeof(addr)); } @@ -135,7 +135,7 @@ static void build_addr(struct ipv6db_addr_t *a, uint64_t intf_id, struct in6_add *(uint64_t *)(addr->s6_addr + 8) |= intf_id & ((1 << (128 - a->prefix_len)) - 1); } -static void insert_dp_routes(struct ppp_t *ppp, struct dhcpv6_pd *pd) +static void insert_dp_routes(struct ap_session *ses, struct dhcpv6_pd *pd) { struct ipv6db_addr_t *a; struct ipv6db_addr_t *p; @@ -145,7 +145,7 @@ static void insert_dp_routes(struct ppp_t *ppp, struct dhcpv6_pd *pd) int err; memset(&rt6, 0, sizeof(rt6)); - rt6.rtmsg_ifindex = ppp->ifindex; + rt6.rtmsg_ifindex = ses->ifindex; rt6.rtmsg_flags = RTF_UP; list_for_each_entry(p, &pd->ipv6_dp->prefix_list, entry) { @@ -155,8 +155,8 @@ static void insert_dp_routes(struct ppp_t *ppp, struct dhcpv6_pd *pd) if (conf_route_via_gw) { rt6.rtmsg_flags |= RTF_GATEWAY; - list_for_each_entry(a, &ppp->ipv6->addr_list, entry) { - build_addr(a, ppp->ipv6->peer_intf_id, &rt6.rtmsg_gateway); + list_for_each_entry(a, &ses->ipv6->addr_list, entry) { + build_addr(a, ses->ipv6->peer_intf_id, &rt6.rtmsg_gateway); if (ioctl(sock6_fd, SIOCADDRT, &rt6)) { err = errno; inet_ntop(AF_INET6, &p->addr, str1, sizeof(str1)); @@ -252,7 +252,7 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i if (req->hdr->type == D6_RENEW && pd->addr_iaid != ia_na->iaid) { insert_status(reply, opt1, D6_STATUS_NoBinding); - } else if (list_empty(&req->ppp->ipv6->addr_list) || f) { + } else if (list_empty(&req->ses->ipv6->addr_list) || f) { insert_status(reply, opt1, D6_STATUS_NoAddrsAvail); } else { @@ -261,11 +261,11 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i f = 1; - list_for_each_entry(a, &req->ppp->ipv6->addr_list, entry) { + list_for_each_entry(a, &req->ses->ipv6->addr_list, entry) { opt2 = dhcpv6_nested_option_alloc(reply, opt1, D6_OPTION_IAADDR, sizeof(*ia_addr) - sizeof(struct dhcpv6_opt_hdr)); ia_addr = (struct dhcpv6_opt_ia_addr *)opt2->hdr; - build_addr(a, req->ppp->ipv6->peer_intf_id, &ia_addr->addr); + build_addr(a, req->ses->ipv6->peer_intf_id, &ia_addr->addr); ia_addr->pref_lifetime = htonl(conf_pref_lifetime); ia_addr->valid_lifetime = htonl(conf_valid_lifetime); @@ -279,8 +279,8 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i continue; f1 = 0; - list_for_each_entry(a, &req->ppp->ipv6->addr_list, entry) { - build_addr(a, req->ppp->ipv6->peer_intf_id, &addr); + list_for_each_entry(a, &req->ses->ipv6->addr_list, entry) { + build_addr(a, req->ses->ipv6->peer_intf_id, &addr); if (memcmp(&addr, &ia_addr->addr, sizeof(addr))) continue; f1 = 1; @@ -316,7 +316,7 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i ia_na->T2 = conf_pref_lifetime == -1 ? -1 : htonl((conf_pref_lifetime * 4) / 5); if (!pd->ipv6_dp) - pd->ipv6_dp = ipdb_get_ipv6_prefix(req->ppp); + pd->ipv6_dp = ipdb_get_ipv6_prefix(req->ses); if ((req->hdr->type == D6_RENEW) && pd->dp_iaid != ia_na->iaid) { insert_status(reply, opt1, D6_STATUS_NoBinding); @@ -327,7 +327,7 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i if (req->hdr->type == D6_REQUEST || req->rapid_commit) { pd->dp_iaid = ia_na->iaid; if (!pd->dp_active) - insert_dp_routes(req->ppp, pd); + insert_dp_routes(req->ses, pd); } f2 = 1; @@ -447,8 +447,8 @@ static void dhcpv6_send_reply2(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, f1 = 0; if (!f) { - list_for_each_entry(a, &req->ppp->ipv6->addr_list, entry) { - build_addr(a, req->ppp->ipv6->peer_intf_id, &addr); + list_for_each_entry(a, &req->ses->ipv6->addr_list, entry) { + build_addr(a, req->ses->ipv6->peer_intf_id, &addr); if (memcmp(&addr, &ia_addr->addr, sizeof(addr))) continue; f1 = 1; @@ -489,7 +489,7 @@ static void dhcpv6_send_reply2(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, ia_na->T2 = conf_pref_lifetime == -1 ? -1 : htonl((conf_pref_lifetime * 4) / 5); if (!pd->ipv6_dp) - pd->ipv6_dp = ipdb_get_ipv6_prefix(req->ppp); + pd->ipv6_dp = ipdb_get_ipv6_prefix(req->ses); f3 = 0; @@ -558,7 +558,7 @@ static void dhcpv6_send_reply2(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, static void dhcpv6_recv_solicit(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (!pd) return; @@ -590,7 +590,7 @@ static void dhcpv6_recv_solicit(struct dhcpv6_packet *req) static void dhcpv6_recv_request(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (!pd) return; @@ -618,7 +618,7 @@ static void dhcpv6_recv_request(struct dhcpv6_packet *req) static void dhcpv6_recv_renew(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (!pd) return; @@ -655,7 +655,7 @@ static void dhcpv6_recv_renew(struct dhcpv6_packet *req) static void dhcpv6_recv_information_request(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (req->rapid_commit) { log_ppp_error("dhcpv6: unexpected Rapid-Commit option\n"); @@ -669,7 +669,7 @@ static void dhcpv6_recv_information_request(struct dhcpv6_packet *req) static void dhcpv6_recv_rebind(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (!pd) return; @@ -747,7 +747,7 @@ static int dhcpv6_read(struct triton_md_handler_t *h) struct sockaddr_in6 addr; socklen_t len = sizeof(addr); struct dhcpv6_packet *pkt; - struct ppp_t *ppp; + struct ap_session *ses; while (1) { n = recvfrom(h->fd, buf, BUF_SIZE, 0, &addr, &len); @@ -768,26 +768,26 @@ static int dhcpv6_read(struct triton_md_handler_t *h) continue; } - pthread_rwlock_rdlock(&ppp_lock); - list_for_each_entry(ppp, &ppp_list, entry) { - if (ppp->state != PPP_STATE_ACTIVE) + pthread_rwlock_rdlock(&ses_lock); + list_for_each_entry(ses, &ses_list, entry) { + if (ses->state != AP_STATE_ACTIVE) continue; - if (!ppp->ipv6) + if (!ses->ipv6) continue; - if (ppp->ifindex != addr.sin6_scope_id) + if (ses->ifindex != addr.sin6_scope_id) continue; - if (ppp->ipv6->peer_intf_id != *(uint64_t *)(addr.sin6_addr.s6_addr + 8)) + if (ses->ipv6->peer_intf_id != *(uint64_t *)(addr.sin6_addr.s6_addr + 8)) continue; - pkt->ppp = ppp; + pkt->ses = ses; - triton_context_call(ppp->ctrl->ctx, (triton_event_func)dhcpv6_recv_packet, pkt); + triton_context_call(ses->ctrl->ctx, (triton_event_func)dhcpv6_recv_packet, pkt); break; } - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); } return 0; @@ -991,8 +991,8 @@ static void init(void) triton_context_wakeup(&dhcpv6_ctx); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); - triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)ev_ppp_started); - triton_event_register_handler(EV_PPP_FINISHED, (triton_event_func)ev_ppp_finished); + triton_event_register_handler(EV_SES_STARTED, (triton_event_func)ev_ppp_started); + triton_event_register_handler(EV_SES_FINISHED, (triton_event_func)ev_ppp_finished); } DEFINE_INIT(10, init); diff --git a/accel-pppd/ipv6/dhcpv6.h b/accel-pppd/ipv6/dhcpv6.h index d1c0267c..4afb5fa6 100644 --- a/accel-pppd/ipv6/dhcpv6.h +++ b/accel-pppd/ipv6/dhcpv6.h @@ -167,7 +167,7 @@ struct dhcpv6_option struct ppp_t; struct dhcpv6_packet { - struct ppp_t *ppp; + struct ap_session *ses; struct dhcpv6_msg_hdr *hdr; struct dhcpv6_opt_clientid *clientid; diff --git a/accel-pppd/ipv6/dhcpv6_packet.c b/accel-pppd/ipv6/dhcpv6_packet.c index 026b6afd..71184911 100644 --- a/accel-pppd/ipv6/dhcpv6_packet.c +++ b/accel-pppd/ipv6/dhcpv6_packet.c @@ -212,7 +212,7 @@ struct dhcpv6_packet *dhcpv6_packet_alloc_reply(struct dhcpv6_packet *req, int t memset(pkt, 0, sizeof(*pkt)); INIT_LIST_HEAD(&pkt->opt_list); - pkt->ppp = req->ppp; + pkt->ses = req->ses; pkt->hdr = _malloc(BUF_SIZE); if (!pkt->hdr) { diff --git a/accel-pppd/ipv6/nd.c b/accel-pppd/ipv6/nd.c index e6040a07..79a228cb 100644 --- a/accel-pppd/ipv6/nd.c +++ b/accel-pppd/ipv6/nd.c @@ -79,8 +79,8 @@ struct nd_opt_dnssl_info_local struct ipv6_nd_handler_t { - struct ppp_t *ppp; - struct ppp_pd_t pd; + struct ap_session *ses; + struct ap_private pd; struct triton_md_handler_t hnd; struct triton_timer_t timer; int ra_sent; @@ -120,7 +120,7 @@ static void ipv6_nd_send_ra(struct ipv6_nd_handler_t *h, struct sockaddr_in6 *ad adv->nd_ra_retransmit = htonl(conf_AdvRetransTimer); pinfo = (struct nd_opt_prefix_info *)(adv + 1); - list_for_each_entry(a, &h->ppp->ipv6->addr_list, entry) { + list_for_each_entry(a, &h->ses->ipv6->addr_list, entry) { if (a->prefix_len > 64) continue; @@ -136,7 +136,7 @@ static void ipv6_nd_send_ra(struct ipv6_nd_handler_t *h, struct sockaddr_in6 *ad } /*rinfo = (struct nd_opt_route_info_local *)pinfo; - list_for_each_entry(a, &h->ppp->ipv6->route_list, entry) { + list_for_each_entry(a, &h->ses->ipv6->route_list, entry) { memset(rinfo, 0, sizeof(*rinfo)); rinfo->nd_opt_ri_type = ND_OPT_ROUTE_INFORMATION; rinfo->nd_opt_ri_len = 3; @@ -186,7 +186,7 @@ static void send_ra_timer(struct triton_timer_t *t) addr.sin6_family = AF_INET6; addr.sin6_addr.s6_addr32[0] = htonl(0xff020000); addr.sin6_addr.s6_addr32[3] = htonl(0x1); - addr.sin6_scope_id = h->ppp->ifindex; + addr.sin6_scope_id = h->ses->ifindex; if (h->ra_sent++ == conf_init_ra) { h->timer.period = conf_MaxRtrAdvInterval * 1000; @@ -233,7 +233,7 @@ static int ipv6_nd_read(struct triton_md_handler_t *_h) continue; } - /*if (*(uint64_t *)(addr.sin6_addr.s6_addr + 8) != *(uint64_t *)(h->ppp->ipv6_addr.s6_addr + 8)) { + /*if (*(uint64_t *)(addr.sin6_addr.s6_addr + 8) != *(uint64_t *)(h->ses->ipv6_addr.s6_addr + 8)) { log_ppp_warn("ipv6_nd: received icmp packet from unknown address\n"); continue; }*/ @@ -246,7 +246,7 @@ static int ipv6_nd_read(struct triton_md_handler_t *_h) return 0; } -static int ipv6_nd_start(struct ppp_t *ppp) +static int ipv6_nd_start(struct ap_session *ses) { int sock; struct icmp6_filter filter; @@ -267,8 +267,8 @@ static int ipv6_nd_start(struct ppp_t *ppp) memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_addr.s6_addr32[0] = htons(0xfe80); - *(uint64_t *)(addr.sin6_addr.s6_addr + 8) = ppp->ipv6->intf_id; - addr.sin6_scope_id = ppp->ifindex; + *(uint64_t *)(addr.sin6_addr.s6_addr + 8) = ses->ipv6->intf_id; + addr.sin6_scope_id = ses->ifindex; if (bind(sock, (struct sockaddr *)&addr, sizeof(addr))) { log_ppp_error("ipv6_nd: bind: %s %i\n", strerror(errno), errno); @@ -307,7 +307,7 @@ static int ipv6_nd_start(struct ppp_t *ppp) } memset(&mreq, 0, sizeof(mreq)); - mreq.ipv6mr_interface = ppp->ifindex; + mreq.ipv6mr_interface = ses->ifindex; mreq.ipv6mr_multiaddr.s6_addr32[0] = htonl(0xff020000); mreq.ipv6mr_multiaddr.s6_addr32[3] = htonl(0x2); @@ -320,18 +320,18 @@ static int ipv6_nd_start(struct ppp_t *ppp) h = _malloc(sizeof(*h)); memset(h, 0, sizeof(*h)); - h->ppp = ppp; + h->ses = ses; h->pd.key = &pd_key; h->hnd.fd = sock; h->hnd.read = ipv6_nd_read; h->timer.expire = send_ra_timer; h->timer.period = conf_init_ra_interval * 1000; - list_add_tail(&h->pd.entry, &ppp->pd_list); + list_add_tail(&h->pd.entry, &ses->pd_list); - triton_md_register_handler(ppp->ctrl->ctx, &h->hnd); + triton_md_register_handler(ses->ctrl->ctx, &h->hnd); triton_md_enable_handler(&h->hnd, MD_MODE_READ); - triton_timer_add(ppp->ctrl->ctx, &h->timer, 0); + triton_timer_add(ses->ctrl->ctx, &h->timer, 0); return 0; @@ -340,11 +340,11 @@ out_err: return -1; } -static struct ipv6_nd_handler_t *find_pd(struct ppp_t *ppp) +static struct ipv6_nd_handler_t *find_pd(struct ap_session *ses) { - struct ppp_pd_t *pd; + struct ap_private *pd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == &pd_key) return container_of(pd, typeof(struct ipv6_nd_handler_t), pd); } @@ -352,17 +352,17 @@ static struct ipv6_nd_handler_t *find_pd(struct ppp_t *ppp) return NULL; } -static void ev_ppp_started(struct ppp_t *ppp) +static void ev_ses_started(struct ap_session *ses) { - if (!ppp->ipv6) + if (!ses->ipv6) return; - ipv6_nd_start(ppp); + ipv6_nd_start(ses); } -static void ev_ppp_finishing(struct ppp_t *ppp) +static void ev_ses_finishing(struct ap_session *ses) { - struct ipv6_nd_handler_t *h = find_pd(ppp); + struct ipv6_nd_handler_t *h = find_pd(ses); if (!h) return; @@ -531,8 +531,8 @@ static void init(void) load_config(); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); - triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)ev_ppp_started); - triton_event_register_handler(EV_PPP_FINISHING, (triton_event_func)ev_ppp_finishing); + triton_event_register_handler(EV_SES_STARTED, (triton_event_func)ev_ses_started); + triton_event_register_handler(EV_SES_FINISHING, (triton_event_func)ev_ses_finishing); } DEFINE_INIT(5, init); |