/***************************************************************************** * pppoe.c - PPP Over Ethernet implementation for lwIP. * * Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc. * * The authors hereby grant permission to use, copy, modify, distribute, * and license this software and its documentation for any purpose, provided * that existing copyright notices are retained in all copies and that this * notice and the following disclaimer are included verbatim in any * distributions. No written agreement, license, or royalty fee is required * for any of the authorized uses. * * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** * REVISION HISTORY * * 06-01-01 Marc Boucher * Ported to lwIP. *****************************************************************************/ /* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Martin Husemann . * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "netif/ppp/ppp_opts.h" #if PPP_SUPPORT && PPPOE_SUPPORT /* don't build if not configured for use in lwipopts.h */ #if 0 /* UNUSED */ #include #include #endif /* UNUSED */ #include "lwip/timeouts.h" #include "lwip/memp.h" #include "lwip/stats.h" #include "lwip/snmp.h" #include "netif/ethernet.h" #include "netif/ppp/ppp_impl.h" #include "netif/ppp/lcp.h" #include "netif/ppp/ipcp.h" #include "netif/ppp/pppoe.h" /* Memory pool */ LWIP_MEMPOOL_DECLARE(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_softc), "PPPOE_IF") /* Add a 16 bit unsigned value to a buffer pointed to by PTR */ #define PPPOE_ADD_16(PTR, VAL) \ *(PTR)++ = (u8_t)((VAL) / 256); \ *(PTR)++ = (u8_t)((VAL) % 256) /* Add a complete PPPoE header to the buffer pointed to by PTR */ #define PPPOE_ADD_HEADER(PTR, CODE, SESS, LEN) \ *(PTR)++ = PPPOE_VERTYPE; \ *(PTR)++ = (CODE); \ PPPOE_ADD_16(PTR, SESS); \ PPPOE_ADD_16(PTR, LEN) #define PPPOE_DISC_TIMEOUT (5*1000) /* base for quick timeout calculation */ #define PPPOE_SLOW_RETRY (60*1000) /* persistent retry interval */ #define PPPOE_DISC_MAXPADI 4 /* retry PADI four times (quickly) */ #define PPPOE_DISC_MAXPADR 2 /* retry PADR twice */ #ifdef PPPOE_SERVER #error "PPPOE_SERVER is not yet supported under lwIP!" /* from if_spppsubr.c */ #define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */ #endif #define PPPOE_ERRORSTRING_LEN 64 /* callbacks called from PPP core */ static err_t pppoe_write(ppp_pcb *ppp, void *ctx, struct pbuf *p); static err_t pppoe_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, u_short protocol); static void pppoe_connect(ppp_pcb *ppp, void *ctx); static void pppoe_disconnect(ppp_pcb *ppp, void *ctx); static err_t pppoe_destroy(ppp_pcb *ppp, void *ctx); /* management routines */ static void pppoe_abort_connect(struct pppoe_softc *); #if 0 /* UNUSED */ static void pppoe_clear_softc(struct pppoe_softc *, const char *); #endif /* UNUSED */ /* internal timeout handling */ static void pppoe_timeout(void *); /* sending actual protocol controll packets */ static err_t pppoe_send_padi(struct pppoe_softc *); static err_t pppoe_send_padr(struct pppoe_softc *); #ifdef PPPOE_SERVER static err_t pppoe_send_pado(struct pppoe_softc *); static err_t pppoe_send_pads(struct pppoe_softc *); #endif static err_t pppoe_send_padt(struct netif *, u_int, const u8_t *); /* internal helper functions */ static err_t pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb); static struct pppoe_softc* pppoe_find_softc_by_session(u_int session, struct netif *rcvif); static struct pppoe_softc* pppoe_find_softc_by_hunique(u8_t *token, size_t len, struct netif *rcvif); /** linked list of created pppoe interfaces */ static struct pppoe_softc *pppoe_softc_list; /* Callbacks structure for PPP core */ static const struct link_callbacks pppoe_callbacks = { pppoe_connect, #if PPP_SERVER NULL, #endif /* PPP_SERVER */ pppoe_disconnect, pppoe_destroy, pppoe_write, pppoe_netif_output, NULL, NULL }; /* * Create a new PPP Over Ethernet (PPPoE) connection. * * Return 0 on success, an error code on failure. */ ppp_pcb *pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name, const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, void *ctx_cb) { ppp_pcb *ppp; struct pppoe_softc *sc; LWIP_UNUSED_ARG(service_name); LWIP_UNUSED_ARG(concentrator_name); sc = (struct pppoe_softc *)LWIP_MEMPOOL_ALLOC(PPPOE_IF); if (sc == NULL) { return NULL; } ppp = ppp_new(pppif, &pppoe_callbacks, sc, link_status_cb, ctx_cb); if (ppp == NULL) { LWIP_MEMPOOL_FREE(PPPOE_IF, sc); return NULL; } memset(sc, 0, sizeof(struct pppoe_softc)); sc->pcb = ppp; sc->sc_ethif = ethif; /* put the new interface at the head of the list */ sc->next = pppoe_softc_list; pppoe_softc_list = sc; return ppp; } /* Called by PPP core */ static err_t pppoe_write(ppp_pcb *ppp, void *ctx, struct pbuf *p) { struct pppoe_softc *sc = (struct pppoe_softc *)ctx; struct pbuf *ph; /* Ethernet + PPPoE header */ err_t ret; #if MIB2_STATS u16_t tot_len; #else /* MIB2_STATS */ LWIP_UNUSED_ARG(ppp); #endif /* MIB2_STATS */ /* skip address & flags */ pbuf_header(p, -(s16_t)2); ph = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN), PBUF_RAM); if(!ph) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards); pbuf_free(p); return ERR_MEM; } pbuf_header(ph, -(s16_t)PPPOE_HEADERLEN); /* hide PPPoE header */ pbuf_cat(ph, p); #if MIB2_STATS tot_len = ph->tot_len; #endif /* MIB2_STATS */ ret = pppoe_xmit(sc, ph); if (ret != ERR_OK) { LINK_STATS_INC(link.err); MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards); return ret; } MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, (u16_t)tot_len); MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts); LINK_STATS_INC(link.xmit); return ERR_OK; } /* Called by PPP core */ static err_t pppoe_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, u_short protocol) { struct pppoe_softc *sc = (struct pppoe_softc *)ctx; struct pbuf *pb; u8_t *pl; err_t err; #if MIB2_STATS u16_t tot_len; #else /* MIB2_STATS */ LWIP_UNUSED_ARG(ppp); #endif /* MIB2_STATS */ /* @todo: try to use pbuf_header() here! */ pb = pbuf_alloc(PBUF_LINK, PPPOE_HEADERLEN + sizeof(protocol), PBUF_RAM); if(!pb) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.proterr); MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards); return ERR_MEM; } pbuf_header(pb, -(s16_t)PPPOE_HEADERLEN); pl = (u8_t*)pb->payload; PUTSHORT(protocol, pl); pbuf_chain(pb, p); #if MIB2_STATS tot_len = pb->tot_len; #endif /* MIB2_STATS */ if( (err = pppoe_xmit(sc, pb)) != ERR_OK) { LINK_STATS_INC(link.err); MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards); return err; } MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, tot_len); MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts); LINK_STATS_INC(link.xmit); return ERR_OK; } static err_t pppoe_destroy(ppp_pcb *ppp, void *ctx) { struct pppoe_softc *sc = (struct pppoe_softc *)ctx; struct pppoe_softc **copp, *freep; LWIP_UNUSED_ARG(ppp); sys_untimeout(pppoe_timeout, sc); /* remove interface from list */ for (copp = &pppoe_softc_list; (freep = *copp); copp = &freep->next) { if (freep == sc) { *copp = freep->next; break; } } #ifdef PPPOE_TODO if (sc->sc_concentrator_name) { mem_free(sc->sc_concentrator_name); } if (sc->sc_service_name) { mem_free(sc->sc_service_name); } #endif /* PPPOE_TODO */ LWIP_MEMPOOL_FREE(PPPOE_IF, sc); return ERR_OK; } /* * Find the interface handling the specified session. * Note: O(number of sessions open), this is a client-side only, mean * and lean implementation, so number of open sessions typically should * be 1. */ static struct pppoe_softc* pppoe_find_softc_by_session(u_int session, struct netif *rcvif) { struct pppoe_softc *sc; for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) { if (sc->sc_state == PPPOE_STATE_SESSION && sc->sc_session == session && sc->sc_ethif == rcvif) { return sc; } } return NULL; } /* Check host unique token passed and return appropriate softc pointer, * or NULL if token is bogus. */ static struct pppoe_softc* pppoe_find_softc_by_hunique(u8_t *token, size_t len, struct netif *rcvif) { struct pppoe_softc *sc, *t; if (len != sizeof sc) { return NULL; } MEMCPY(&t, token, len); for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) { if (sc == t) { break; } } if (sc == NULL) { PPPDEBUG(LOG_DEBUG, ("pppoe: alien host unique tag, no session found\n")); return NULL; } /* should be safe to access *sc now */ if (sc->sc_state < PPPOE_STATE_PADI_SENT || sc->sc_state >= PPPOE_STATE_SESSION) { PPPDEBUG(LOG_DEBUG, ("%c%c%"U16_F": host unique tag found, but it belongs to a connection in state %d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_state)); return NULL; } if (sc->sc_ethif != rcvif) { PPPDEBUG(LOG_DEBUG, ("%c%c%"U16_F": wrong interface, not accepting host unique\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); return NULL; } return sc; } /* analyze and handle a single received packet while not in session state */ void pppoe_disc_input(struct netif *netif, struct pbuf *pb) { u16_t tag, len; u16_t session, plen; struct pppoe_softc *sc; #if PPP_DEBUG const char *err_msg = NULL; #endif /* PPP_DEBUG */ u8_t *ac_cookie; u16_t ac_cookie_len; #ifdef PPPOE_SERVER u8_t *hunique; size_t hunique_len; #endif struct pppoehdr *ph; struct pppoetag pt; int off, err; struct eth_hdr *ethhdr; /* don't do anything if there is not a single PPPoE instance */ if (pppoe_softc_list == NULL) { pbuf_free(pb); return; } pb = ppp_singlebuf(pb); if (pb->len < sizeof(*ethhdr)) { goto done; } ethhdr = (struct eth_hdr *)pb->payload; off = sizeof(*ethhdr); ac_cookie = NULL; ac_cookie_len = 0; #ifdef PPPOE_SERVER hunique = NULL; hunique_len = 0; #endif session = 0; if (pb->len - off < (u16_t)PPPOE_HEADERLEN) { PPPDEBUG(LOG_DEBUG, ("pppoe: packet too short: %d\n", pb->len)); goto done; } ph = (struct pppoehdr *) (ethhdr + 1); if (ph->vertype != PPPOE_VERTYPE) { PPPDEBUG(LOG_DEBUG, ("pppoe: unknown version/type packet: 0x%x\n", ph->vertype)); goto done; } session = lwip_ntohs(ph->session); plen = lwip_ntohs(ph->plen); off += sizeof(*ph); if (plen + off > pb->len) { PPPDEBUG(LOG_DEBUG, ("pppoe: packet content does not fit: data available = %d, packet size = %u\n", pb->len - off, plen)); goto done; } if(pb->tot_len == pb->len) { pb->tot_len = pb->len = (u16_t)off + plen; /* ignore trailing garbage */ } tag = 0; len = 0; sc = NULL; while (off + sizeof(pt) <= pb->len) { MEMCPY(&pt, (u8_t*)pb->payload + off, sizeof(pt)); tag = lwip_ntohs(pt.tag); len = lwip_ntohs(pt.len); if (off + sizeof(pt) + len > pb->len) { PPPDEBUG(LOG_DEBUG, ("pppoe: tag 0x%x len 0x%x is too long\n", tag, len)); goto done; } switch (tag) { case PPPOE_TAG_EOL: goto breakbreak; case PPPOE_TAG_SNAME: break; /* ignored */ case PPPOE_TAG_ACNAME: break; /* ignored */ case PPPOE_TAG_HUNIQUE: if (sc != NULL) { break; } #ifdef PPPOE_SERVER hunique = (u8_t*)pb->payload + off + sizeof(pt); hunique_len = len; #endif sc = pppoe_find_softc_by_hunique((u8_t*)pb->payload + off + sizeof(pt), len, netif); break; case PPPOE_TAG_ACCOOKIE: if (ac_cookie == NULL) { if (len > PPPOE_MAX_AC_COOKIE_LEN) { PPPDEBUG(LOG_DEBUG, ("pppoe: AC cookie is too long: len = %d, max = %d\n", len, PPPOE_MAX_AC_COOKIE_LEN)); goto done; } ac_cookie = (u8_t*)pb->payload + off + sizeof(pt); ac_cookie_len = len; } break; #if PPP_DEBUG case PPPOE_TAG_SNAME_ERR: err_msg = "SERVICE NAME ERROR"; break; case PPPOE_TAG_ACSYS_ERR: err_msg = "AC SYSTEM ERROR"; break; case PPPOE_TAG_GENERIC_ERR: err_msg = "GENERIC ERROR"; break; #endif /* PPP_DEBUG */ default: break; } #if PPP_DEBUG if (err_msg != NULL) { char error_tmp[PPPOE_ERRORSTRING_LEN]; u16_t error_len = LWIP_MIN(len, sizeof(error_tmp)-1); strncpy(error_tmp, (char*)pb->payload + off + sizeof(pt), error_len); error_tmp[error_len] = '\0'; if (sc) { PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": %s: %s\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err_msg, error_tmp)); } else { PPPDEBUG(LOG_DEBUG, ("pppoe: %s: %s\n", err_msg, error_tmp)); } } #endif /* PPP_DEBUG */ off += sizeof(pt) + len; } breakbreak:; switch (ph->code) { case PPPOE_CODE_PADI: #ifdef PPPOE_SERVER /* * got service name, concentrator name, and/or host unique. * ignore if we have no interfaces with IFF_PASSIVE|IFF_UP. */ if (LIST_EMPTY(&pppoe_softc_list)) { goto done; } LIST_FOREACH(sc, &pppoe_softc_list, sc_list) { if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP)) { continue; } if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) { continue; } if (sc->sc_state == PPPOE_STATE_INITIAL) { break; } } if (sc == NULL) { /* PPPDEBUG(LOG_DEBUG, ("pppoe: free passive interface is not found\n")); */ goto done; } if (hunique) { if (sc->sc_hunique) { mem_free(sc->sc_hunique); } sc->sc_hunique = mem_malloc(hunique_len); if (sc->sc_hunique == NULL) { goto done; } sc->sc_hunique_len = hunique_len; MEMCPY(sc->sc_hunique, hunique, hunique_len); } MEMCPY(&sc->sc_dest, eh->ether_shost, sizeof sc->sc_dest); sc->sc_state = PPPOE_STATE_PADO_SENT; pppoe_send_pado(sc); break; #endif /* PPPOE_SERVER */ case PPPOE_CODE_PADR: #ifdef PPPOE_SERVER /* * get sc from ac_cookie if IFF_PASSIVE */ if (ac_cookie == NULL) { /* be quiet if there is not a single pppoe instance */ PPPDEBUG(LOG_DEBUG, ("pppoe: received PADR but not includes ac_cookie\n")); goto done; } sc = pppoe_find_softc_by_hunique(ac_cookie, ac_cookie_len, netif); if (sc == NULL) { /* be quiet if there is not a single pppoe instance */ if (!LIST_EMPTY(&pppoe_softc_list)) { PPPDEBUG(LOG_DEBUG, ("pppoe: received PADR but could not find request for it\n")); } goto done; } if (sc->sc_state != PPPOE_STATE_PADO_SENT) { PPPDEBUG(LOG_DEBUG, ("%c%c%"U16_F": received unexpected PADR\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); goto done; } if (hunique) { if (sc->sc_hunique) { mem_free(sc->sc_hunique); } sc->sc_hunique = mem_malloc(hunique_len); if (sc->sc_hunique == NULL) { goto done; } sc->sc_hunique_len = hunique_len; MEMCPY(sc->sc_hunique, hunique, hunique_len); } pppoe_send_pads(sc); sc->sc_state = PPPOE_STATE_SESSION; ppp_start(sc->pcb); /* notify upper layers */ break; #else /* ignore, we are no access concentrator */ goto done; #endif /* PPPOE_SERVER */ case PPPOE_CODE_PADO: if (sc == NULL) { /* be quiet if there is not a single pppoe instance */ if (pppoe_softc_list != NULL) { PPPDEBUG(LOG_DEBUG, ("pppoe: received PADO but could not find request for it\n")); } goto done; } if (sc->sc_state != PPPOE_STATE_PADI_SENT) { PPPDEBUG(LOG_DEBUG, ("%c%c%"U16_F": received unexpected PADO\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); goto done; } if (ac_cookie) { sc->sc_ac_cookie_len = ac_cookie_len; MEMCPY(sc->sc_ac_cookie, ac_cookie, ac_cookie_len); } MEMCPY(&sc->sc_dest, ethhdr->src.addr, sizeof(sc->sc_dest.addr)); sys_untimeout(pppoe_timeout, sc); sc->sc_padr_retried = 0; sc->sc_state = PPPOE_STATE_PADR_SENT; if ((err = pppoe_send_padr(sc)) != 0) { PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err)); } sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc); break; case PPPOE_CODE_PADS: if (sc == NULL) { goto done; } sc->sc_session = session; sys_untimeout(pppoe_timeout, sc); PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": session 0x%x connected\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, session)); sc->sc_state = PPPOE_STATE_SESSION; ppp_start(sc->pcb); /* notify upper layers */ break; case PPPOE_CODE_PADT: /* Don't disconnect here, we let the LCP Echo/Reply find the fact * that PPP session is down. Asking the PPP stack to end the session * require strict checking about the PPP phase to prevent endless * disconnection loops. */ #if 0 /* UNUSED */ if (sc == NULL) { /* PADT frames are rarely sent with a hunique tag, this is actually almost always true */ goto done; } pppoe_clear_softc(sc, "received PADT"); #endif /* UNUSED */ break; default: if(sc) { PPPDEBUG(LOG_DEBUG, ("%c%c%"U16_F": unknown code (0x%"X16_F") session = 0x%"X16_F"\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, (u16_t)ph->code, session)); } else { PPPDEBUG(LOG_DEBUG, ("pppoe: unknown code (0x%"X16_F") session = 0x%"X16_F"\n", (u16_t)ph->code, session)); } break; } done: pbuf_free(pb); return; } void pppoe_data_input(struct netif *netif, struct pbuf *pb) { u16_t session, plen; struct pppoe_softc *sc; struct pppoehdr *ph; #ifdef PPPOE_TERM_UNKNOWN_SESSIONS u8_t shost[ETHER_ADDR_LEN]; #endif #ifdef PPPOE_TERM_UNKNOWN_SESSIONS MEMCPY(shost, ((struct eth_hdr *)pb->payload)->src.addr, sizeof(shost)); #endif if (pbuf_header(pb, -(s16_t)sizeof(struct eth_hdr)) != 0) { /* bail out */ PPPDEBUG(LOG_ERR, ("pppoe_data_input: pbuf_header failed\n")); LINK_STATS_INC(link.lenerr); goto drop; } if (pb->len < sizeof(*ph)) { PPPDEBUG(LOG_DEBUG, ("pppoe_data_input: could not get PPPoE header\n")); goto drop; } ph = (struct pppoehdr *)pb->payload; if (ph->vertype != PPPOE_VERTYPE) { PPPDEBUG(LOG_DEBUG, ("pppoe (data): unknown version/type packet: 0x%x\n", ph->vertype)); goto drop; } if (ph->code != 0) { goto drop; } session = lwip_ntohs(ph->session); sc = pppoe_find_softc_by_session(session, netif); if (sc == NULL) { #ifdef PPPOE_TERM_UNKNOWN_SESSIONS PPPDEBUG(LOG_DEBUG, ("pppoe: input for unknown session 0x%x, sending PADT\n", session)); pppoe_send_padt(netif, session, shost); #endif goto drop; } plen = lwip_ntohs(ph->plen); if (pbuf_header(pb, -(s16_t)(PPPOE_HEADERLEN)) != 0) { /* bail out */ PPPDEBUG(LOG_ERR, ("pppoe_data_input: pbuf_header PPPOE_HEADERLEN failed\n")); LINK_STATS_INC(link.lenerr); goto drop; } PPPDEBUG(LOG_DEBUG, ("pppoe_data_input: %c%c%"U16_F": pkthdr.len=%d, pppoe.len=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, pb->len, plen)); if (pb->tot_len < plen) { goto drop; } /* Dispatch the packet thereby consuming it. */ ppp_input(sc->pcb, pb); return; drop: pbuf_free(pb); } static err_t pppoe_output(struct pppoe_softc *sc, struct pbuf *pb) { struct eth_hdr *ethhdr; u16_t etype; err_t res; /* make room for Ethernet header - should not fail */ if (pbuf_header(pb, (s16_t)(sizeof(struct eth_hdr))) != 0) { /* bail out */ PPPDEBUG(LOG_ERR, ("pppoe: %c%c%"U16_F": pppoe_output: could not allocate room for Ethernet header\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); LINK_STATS_INC(link.lenerr); pbuf_free(pb); return ERR_BUF; } ethhdr = (struct eth_hdr *)pb->payload; etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHTYPE_PPPOE : ETHTYPE_PPPOEDISC; ethhdr->type = lwip_htons(etype); MEMCPY(ðhdr->dest.addr, &sc->sc_dest.addr, sizeof(ethhdr->dest.addr)); MEMCPY(ðhdr->src.addr, &sc->sc_ethif->hwaddr, sizeof(ethhdr->src.addr)); PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F" (%x) state=%d, session=0x%x output -> %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F", len=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, etype, sc->sc_state, sc->sc_session, sc->sc_dest.addr[0], sc->sc_dest.addr[1], sc->sc_dest.addr[2], sc->sc_dest.addr[3], sc->sc_dest.addr[4], sc->sc_dest.addr[5], pb->tot_len)); res = sc->sc_ethif->linkoutput(sc->sc_ethif, pb); pbuf_free(pb); return res; } static err_t pppoe_send_padi(struct pppoe_softc *sc) { struct pbuf *pb; u8_t *p; int len; #ifdef PPPOE_TODO int l1 = 0, l2 = 0; /* XXX: gcc */ #endif /* PPPOE_TODO */ /* calculate length of frame (excluding ethernet header + pppoe header) */ len = 2 + 2 + 2 + 2 + sizeof sc; /* service name tag is required, host unique is send too */ #ifdef PPPOE_TODO if (sc->sc_service_name != NULL) { l1 = (int)strlen(sc->sc_service_name); len += l1; } if (sc->sc_concentrator_name != NULL) { l2 = (int)strlen(sc->sc_concentrator_name); len += 2 + 2 + l2; } #endif /* PPPOE_TODO */ LWIP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff", sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff); /* allocate a buffer */ pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); if (!pb) { return ERR_MEM; } LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; /* fill in pkt */ PPPOE_ADD_HEADER(p, PPPOE_CODE_PADI, 0, (u16_t)len); PPPOE_ADD_16(p, PPPOE_TAG_SNAME); #ifdef PPPOE_TODO if (sc->sc_service_name != NULL) { PPPOE_ADD_16(p, l1); MEMCPY(p, sc->sc_service_name, l1); p += l1; } else #endif /* PPPOE_TODO */ { PPPOE_ADD_16(p, 0); } #ifdef PPPOE_TODO if (sc->sc_concentrator_name != NULL) { PPPOE_ADD_16(p, PPPOE_TAG_ACNAME); PPPOE_ADD_16(p, l2); MEMCPY(p, sc->sc_concentrator_name, l2); p += l2; } #endif /* PPPOE_TODO */ PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE); PPPOE_ADD_16(p, sizeof(sc)); MEMCPY(p, &sc, sizeof sc); /* send pkt */ return pppoe_output(sc, pb); } static void pppoe_timeout(void *arg) { u32_t retry_wait; int err; struct pppoe_softc *sc = (struct pppoe_softc*)arg; PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": timeout\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); switch (sc->sc_state) { case PPPOE_STATE_PADI_SENT: /* * We have two basic ways of retrying: * - Quick retry mode: try a few times in short sequence * - Slow retry mode: we already had a connection successfully * established and will try infinitely (without user * intervention) * We only enter slow retry mode if IFF_LINK1 (aka autodial) * is not set. */ if (sc->sc_padi_retried < 0xff) { sc->sc_padi_retried++; } if (!sc->pcb->settings.persist && sc->sc_padi_retried >= PPPOE_DISC_MAXPADI) { #if 0 if ((sc->sc_sppp.pp_if.if_flags & IFF_LINK1) == 0) { /* slow retry mode */ retry_wait = PPPOE_SLOW_RETRY; } else #endif { pppoe_abort_connect(sc); return; } } /* initialize for quick retry mode */ retry_wait = LWIP_MIN(PPPOE_DISC_TIMEOUT * sc->sc_padi_retried, PPPOE_SLOW_RETRY); if ((err = pppoe_send_padi(sc)) != 0) { sc->sc_padi_retried--; PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to transmit PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err)); } sys_timeout(retry_wait, pppoe_timeout, sc); break; case PPPOE_STATE_PADR_SENT: sc->sc_padr_retried++; if (sc->sc_padr_retried >= PPPOE_DISC_MAXPADR) { MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); sc->sc_state = PPPOE_STATE_PADI_SENT; sc->sc_padr_retried = 0; if ((err = pppoe_send_padi(sc)) != 0) { PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err)); } sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), pppoe_timeout, sc); return; } if ((err = pppoe_send_padr(sc)) != 0) { sc->sc_padr_retried--; PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADR, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err)); } sys_timeout(PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried), pppoe_timeout, sc); break; default: return; /* all done, work in peace */ } } /* Start a connection (i.e. initiate discovery phase) */ static void pppoe_connect(ppp_pcb *ppp, void *ctx) { err_t err; struct pppoe_softc *sc = (struct pppoe_softc *)ctx; lcp_options *lcp_wo; lcp_options *lcp_ao; #if PPP_IPV4_SUPPORT && VJ_SUPPORT ipcp_options *ipcp_wo; ipcp_options *ipcp_ao; #endif /* PPP_IPV4_SUPPORT && VJ_SUPPORT */ sc->sc_session = 0; sc->sc_ac_cookie_len = 0; sc->sc_padi_retried = 0; sc->sc_padr_retried = 0; /* changed to real address later */ MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); #ifdef PPPOE_SERVER /* wait PADI if IFF_PASSIVE */ if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) { return 0; } #endif lcp_wo = &ppp->lcp_wantoptions; lcp_wo->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ lcp_wo->neg_asyncmap = 0; lcp_wo->neg_pcompression = 0; lcp_wo->neg_accompression = 0; lcp_wo->passive = 0; lcp_wo->silent = 0; lcp_ao = &ppp->lcp_allowoptions; lcp_ao->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ lcp_ao->neg_asyncmap = 0; lcp_ao->neg_pcompression = 0; lcp_ao->neg_accompression = 0; #if PPP_IPV4_SUPPORT && VJ_SUPPORT ipcp_wo = &ppp->ipcp_wantoptions; ipcp_wo->neg_vj = 0; ipcp_wo->old_vj = 0; ipcp_ao = &ppp->ipcp_allowoptions; ipcp_ao->neg_vj = 0; ipcp_ao->old_vj = 0; #endif /* PPP_IPV4_SUPPORT && VJ_SUPPORT */ /* save state, in case we fail to send PADI */ sc->sc_state = PPPOE_STATE_PADI_SENT; if ((err = pppoe_send_padi(sc)) != 0) { PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADI, error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, err)); } sys_timeout(PPPOE_DISC_TIMEOUT, pppoe_timeout, sc); } /* disconnect */ static void pppoe_disconnect(ppp_pcb *ppp, void *ctx) { struct pppoe_softc *sc = (struct pppoe_softc *)ctx; PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); if (sc->sc_state == PPPOE_STATE_SESSION) { pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest); } /* stop any timer, disconnect can be called while initiating is in progress */ sys_untimeout(pppoe_timeout, sc); sc->sc_state = PPPOE_STATE_INITIAL; #ifdef PPPOE_SERVER if (sc->sc_hunique) { mem_free(sc->sc_hunique); sc->sc_hunique = NULL; /* probably not necessary, if state is initial we shouldn't have to access hunique anyway */ } sc->sc_hunique_len = 0; /* probably not necessary, if state is initial we shouldn't have to access hunique anyway */ #endif ppp_link_end(ppp); /* notify upper layers */ return; } /* Connection attempt aborted */ static void pppoe_abort_connect(struct pppoe_softc *sc) { PPPDEBUG(LOG_DEBUG, ("%c%c%"U16_F": could not establish connection\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); sc->sc_state = PPPOE_STATE_INITIAL; ppp_link_failed(sc->pcb); /* notify upper layers */ } /* Send a PADR packet */ static err_t pppoe_send_padr(struct pppoe_softc *sc) { struct pbuf *pb; u8_t *p; size_t len; #ifdef PPPOE_TODO size_t l1 = 0; /* XXX: gcc */ #endif /* PPPOE_TODO */ len = 2 + 2 + 2 + 2 + sizeof(sc); /* service name, host unique */ #ifdef PPPOE_TODO if (sc->sc_service_name != NULL) { /* service name tag maybe empty */ l1 = strlen(sc->sc_service_name); len += l1; } #endif /* PPPOE_TODO */ if (sc->sc_ac_cookie_len > 0) { len += 2 + 2 + sc->sc_ac_cookie_len; /* AC cookie */ } LWIP_ASSERT("sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff", sizeof(struct eth_hdr) + PPPOE_HEADERLEN + len <= 0xffff); pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); if (!pb) { return ERR_MEM; } LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; PPPOE_ADD_HEADER(p, PPPOE_CODE_PADR, 0, len); PPPOE_ADD_16(p, PPPOE_TAG_SNAME); #ifdef PPPOE_TODO if (sc->sc_service_name != NULL) { PPPOE_ADD_16(p, l1); MEMCPY(p, sc->sc_service_name, l1); p += l1; } else #endif /* PPPOE_TODO */ { PPPOE_ADD_16(p, 0); } if (sc->sc_ac_cookie_len > 0) { PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE); PPPOE_ADD_16(p, sc->sc_ac_cookie_len); MEMCPY(p, sc->sc_ac_cookie, sc->sc_ac_cookie_len); p += sc->sc_ac_cookie_len; } PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE); PPPOE_ADD_16(p, sizeof(sc)); MEMCPY(p, &sc, sizeof sc); return pppoe_output(sc, pb); } /* send a PADT packet */ static err_t pppoe_send_padt(struct netif *outgoing_if, u_int session, const u8_t *dest) { struct pbuf *pb; struct eth_hdr *ethhdr; err_t res; u8_t *p; pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN), PBUF_RAM); if (!pb) { return ERR_MEM; } LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); pbuf_header(pb, (s16_t)sizeof(struct eth_hdr)); ethhdr = (struct eth_hdr *)pb->payload; ethhdr->type = PP_HTONS(ETHTYPE_PPPOEDISC); MEMCPY(ðhdr->dest.addr, dest, sizeof(ethhdr->dest.addr)); MEMCPY(ðhdr->src.addr, &outgoing_if->hwaddr, sizeof(ethhdr->src.addr)); p = (u8_t*)(ethhdr + 1); PPPOE_ADD_HEADER(p, PPPOE_CODE_PADT, session, 0); res = outgoing_if->linkoutput(outgoing_if, pb); pbuf_free(pb); return res; } #ifdef PPPOE_SERVER static err_t pppoe_send_pado(struct pppoe_softc *sc) { struct pbuf *pb; u8_t *p; size_t len; /* calc length */ len = 0; /* include ac_cookie */ len += 2 + 2 + sizeof(sc); /* include hunique */ len += 2 + 2 + sc->sc_hunique_len; pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); if (!pb) { return ERR_MEM; } LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; PPPOE_ADD_HEADER(p, PPPOE_CODE_PADO, 0, len); PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE); PPPOE_ADD_16(p, sizeof(sc)); MEMCPY(p, &sc, sizeof(sc)); p += sizeof(sc); PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE); PPPOE_ADD_16(p, sc->sc_hunique_len); MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len); return pppoe_output(sc, pb); } static err_t pppoe_send_pads(struct pppoe_softc *sc) { struct pbuf *pb; u8_t *p; size_t len, l1 = 0; /* XXX: gcc */ sc->sc_session = mono_time.tv_sec % 0xff + 1; /* calc length */ len = 0; /* include hunique */ len += 2 + 2 + 2 + 2 + sc->sc_hunique_len; /* service name, host unique*/ if (sc->sc_service_name != NULL) { /* service name tag maybe empty */ l1 = strlen(sc->sc_service_name); len += l1; } pb = pbuf_alloc(PBUF_LINK, (u16_t)(PPPOE_HEADERLEN + len), PBUF_RAM); if (!pb) { return ERR_MEM; } LWIP_ASSERT("pb->tot_len == pb->len", pb->tot_len == pb->len); p = (u8_t*)pb->payload; PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len); PPPOE_ADD_16(p, PPPOE_TAG_SNAME); if (sc->sc_service_name != NULL) { PPPOE_ADD_16(p, l1); MEMCPY(p, sc->sc_service_name, l1); p += l1; } else { PPPOE_ADD_16(p, 0); } PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE); PPPOE_ADD_16(p, sc->sc_hunique_len); MEMCPY(p, sc->sc_hunique, sc->sc_hunique_len); return pppoe_output(sc, pb); } #endif static err_t pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb) { u8_t *p; size_t len; len = pb->tot_len; /* make room for PPPoE header - should not fail */ if (pbuf_header(pb, (s16_t)(PPPOE_HEADERLEN)) != 0) { /* bail out */ PPPDEBUG(LOG_ERR, ("pppoe: %c%c%"U16_F": pppoe_xmit: could not allocate room for PPPoE header\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); LINK_STATS_INC(link.lenerr); pbuf_free(pb); return ERR_BUF; } p = (u8_t*)pb->payload; PPPOE_ADD_HEADER(p, 0, sc->sc_session, len); return pppoe_output(sc, pb); } #if 0 /*def PFIL_HOOKS*/ static int pppoe_ifattach_hook(void *arg, struct pbuf **mp, struct netif *ifp, int dir) { struct pppoe_softc *sc; int s; if (mp != (struct pbuf **)PFIL_IFNET_DETACH) { return 0; } LIST_FOREACH(sc, &pppoe_softc_list, sc_list) { if (sc->sc_ethif != ifp) { continue; } if (sc->sc_sppp.pp_if.if_flags & IFF_UP) { sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING); PPPDEBUG(LOG_DEBUG, ("%c%c%"U16_F": ethernet interface detached, going down\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); } sc->sc_ethif = NULL; pppoe_clear_softc(sc, "ethernet interface detached"); } return 0; } #endif #if 0 /* UNUSED */ static void pppoe_clear_softc(struct pppoe_softc *sc, const char *message) { LWIP_UNUSED_ARG(message); /* stop timer */ sys_untimeout(pppoe_timeout, sc); PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": session 0x%x terminated, %s\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_session, message)); sc->sc_state = PPPOE_STATE_INITIAL; ppp_link_end(sc->pcb); /* notify upper layers - /!\ dangerous /!\ - see pppoe_disc_input() */ } #endif /* UNUSED */ #endif /* PPP_SUPPORT && PPPOE_SUPPORT */ href='#n1004'>1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557