Deleted Added
full compact
ng_pppoe.c (106624) ng_pppoe.c (109623)
1
2/*
3 * ng_pppoe.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 22 unchanged lines hidden (view full) ---

31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 *
37 * Author: Julian Elischer <julian@freebsd.org>
38 *
1
2/*
3 * ng_pppoe.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 22 unchanged lines hidden (view full) ---

31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 *
37 * Author: Julian Elischer <julian@freebsd.org>
38 *
39 * $FreeBSD: head/sys/netgraph/ng_pppoe.c 106624 2002-11-08 14:50:44Z jhb $
39 * $FreeBSD: head/sys/netgraph/ng_pppoe.c 109623 2003-01-21 08:56:16Z alfred $
40 * $Whistle: ng_pppoe.c,v 1.10 1999/11/01 09:24:52 julian Exp $
41 */
42#if 0
43#define AAA printf("pppoe: %s\n", __func__ );
44#define BBB printf("-%d-", __LINE__ );
45#else
46#define AAA
47#define BBB

--- 670 unchanged lines hidden (view full) ---

718 */
719 MALLOC(neg, negp, sizeof(*neg), M_NETGRAPH_PPPOE,
720 M_NOWAIT | M_ZERO);
721
722 if (neg == NULL) {
723 printf("pppoe: Session out of memory\n");
724 LEAVE(ENOMEM);
725 }
40 * $Whistle: ng_pppoe.c,v 1.10 1999/11/01 09:24:52 julian Exp $
41 */
42#if 0
43#define AAA printf("pppoe: %s\n", __func__ );
44#define BBB printf("-%d-", __LINE__ );
45#else
46#define AAA
47#define BBB

--- 670 unchanged lines hidden (view full) ---

718 */
719 MALLOC(neg, negp, sizeof(*neg), M_NETGRAPH_PPPOE,
720 M_NOWAIT | M_ZERO);
721
722 if (neg == NULL) {
723 printf("pppoe: Session out of memory\n");
724 LEAVE(ENOMEM);
725 }
726 MGETHDR(neg->m, M_DONTWAIT, MT_DATA);
726 MGETHDR(neg->m, M_NOWAIT, MT_DATA);
727 if(neg->m == NULL) {
728 printf("pppoe: Session out of mbufs\n");
729 FREE(neg, M_NETGRAPH_PPPOE);
730 LEAVE(ENOBUFS);
731 }
732 neg->m->m_pkthdr.rcvif = NULL;
727 if(neg->m == NULL) {
728 printf("pppoe: Session out of mbufs\n");
729 FREE(neg, M_NETGRAPH_PPPOE);
730 LEAVE(ENOBUFS);
731 }
732 neg->m->m_pkthdr.rcvif = NULL;
733 MCLGET(neg->m, M_DONTWAIT);
733 MCLGET(neg->m, M_NOWAIT);
734 if ((neg->m->m_flags & M_EXT) == 0) {
735 printf("pppoe: Session out of mcls\n");
736 m_freem(neg->m);
737 FREE(neg, M_NETGRAPH_PPPOE);
738 LEAVE(ENOBUFS);
739 }
740 sp->neg = neg;
741 callout_handle_init( &neg->timeout_handle);

--- 261 unchanged lines hidden (view full) ---

1003 }
1004 if (m->m_len != m->m_pkthdr.len) {
1005 /*
1006 * It's not all in one piece.
1007 * We need to do extra work.
1008 * Put it into a cluster.
1009 */
1010 struct mbuf *n;
734 if ((neg->m->m_flags & M_EXT) == 0) {
735 printf("pppoe: Session out of mcls\n");
736 m_freem(neg->m);
737 FREE(neg, M_NETGRAPH_PPPOE);
738 LEAVE(ENOBUFS);
739 }
740 sp->neg = neg;
741 callout_handle_init( &neg->timeout_handle);

--- 261 unchanged lines hidden (view full) ---

1003 }
1004 if (m->m_len != m->m_pkthdr.len) {
1005 /*
1006 * It's not all in one piece.
1007 * We need to do extra work.
1008 * Put it into a cluster.
1009 */
1010 struct mbuf *n;
1011 n = m_dup(m, M_DONTWAIT);
1011 n = m_dup(m, M_NOWAIT);
1012 m_freem(m);
1013 m = n;
1014 if (m) {
1015 /* just check we got a cluster */
1016 if (m->m_len != m->m_pkthdr.len) {
1017 m_freem(m);
1018 m = NULL;
1019 }

--- 325 unchanged lines hidden (view full) ---

1345 m_adj(m, 2);
1346 }
1347 /*
1348 * Bang in a pre-made header, and set the length up
1349 * to be correct. Then send it to the ethernet driver.
1350 * But first correct the length.
1351 */
1352 sp->pkt_hdr.ph.length = htons((short)(m->m_pkthdr.len));
1012 m_freem(m);
1013 m = n;
1014 if (m) {
1015 /* just check we got a cluster */
1016 if (m->m_len != m->m_pkthdr.len) {
1017 m_freem(m);
1018 m = NULL;
1019 }

--- 325 unchanged lines hidden (view full) ---

1345 m_adj(m, 2);
1346 }
1347 /*
1348 * Bang in a pre-made header, and set the length up
1349 * to be correct. Then send it to the ethernet driver.
1350 * But first correct the length.
1351 */
1352 sp->pkt_hdr.ph.length = htons((short)(m->m_pkthdr.len));
1353 M_PREPEND(m, sizeof(*wh), M_DONTWAIT);
1353 M_PREPEND(m, sizeof(*wh), M_NOWAIT);
1354 if (m == NULL) {
1355 LEAVE(ENOBUFS);
1356 }
1357 wh = mtod(m, struct pppoe_full_hdr *);
1358 bcopy(&sp->pkt_hdr, wh, sizeof(*wh));
1359 NG_FWD_NEW_DATA( error, item, privp->ethernet_hook, m);
1360 privp->packets_out++;
1361 break;

--- 158 unchanged lines hidden (view full) ---

1520 wh = &sp->pkt_hdr;
1521 wh->ph.code = PADT_CODE;
1522 if (nonstandard)
1523 wh->eh.ether_type = ETHERTYPE_PPPOE_STUPID_DISC;
1524 else
1525 wh->eh.ether_type = ETHERTYPE_PPPOE_DISC;
1526
1527 /* generate a packet of that type */
1354 if (m == NULL) {
1355 LEAVE(ENOBUFS);
1356 }
1357 wh = mtod(m, struct pppoe_full_hdr *);
1358 bcopy(&sp->pkt_hdr, wh, sizeof(*wh));
1359 NG_FWD_NEW_DATA( error, item, privp->ethernet_hook, m);
1360 privp->packets_out++;
1361 break;

--- 158 unchanged lines hidden (view full) ---

1520 wh = &sp->pkt_hdr;
1521 wh->ph.code = PADT_CODE;
1522 if (nonstandard)
1523 wh->eh.ether_type = ETHERTYPE_PPPOE_STUPID_DISC;
1524 else
1525 wh->eh.ether_type = ETHERTYPE_PPPOE_DISC;
1526
1527 /* generate a packet of that type */
1528 MGETHDR(m, M_DONTWAIT, MT_DATA);
1528 MGETHDR(m, M_NOWAIT, MT_DATA);
1529 if(m == NULL)
1530 printf("pppoe: Session out of mbufs\n");
1531 else {
1532 m->m_pkthdr.rcvif = NULL;
1533 m->m_pkthdr.len = m->m_len = sizeof(*wh);
1534 bcopy((caddr_t)wh, mtod(m, caddr_t),
1535 sizeof(*wh));
1536 /*

--- 54 unchanged lines hidden (view full) ---

1591 /*
1592 * resend the last packet, using an exponential backoff.
1593 * After a period of time, stop growing the backoff,
1594 * and either leave it, or revert to the start.
1595 */
1596 case PPPOE_SINIT:
1597 case PPPOE_SREQ:
1598 /* timeouts on these produce resends */
1529 if(m == NULL)
1530 printf("pppoe: Session out of mbufs\n");
1531 else {
1532 m->m_pkthdr.rcvif = NULL;
1533 m->m_pkthdr.len = m->m_len = sizeof(*wh);
1534 bcopy((caddr_t)wh, mtod(m, caddr_t),
1535 sizeof(*wh));
1536 /*

--- 54 unchanged lines hidden (view full) ---

1591 /*
1592 * resend the last packet, using an exponential backoff.
1593 * After a period of time, stop growing the backoff,
1594 * and either leave it, or revert to the start.
1595 */
1596 case PPPOE_SINIT:
1597 case PPPOE_SREQ:
1598 /* timeouts on these produce resends */
1599 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1599 m0 = m_copypacket(sp->neg->m, M_NOWAIT);
1600 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1601 neg->timeout_handle = timeout(pppoe_ticker,
1602 hook, neg->timeout * hz);
1603 if ((neg->timeout <<= 1) > PPPOE_TIMEOUT_LIMIT) {
1604 if (sp->state == PPPOE_SREQ) {
1605 /* revert to SINIT mode */
1606 pppoe_start(sp);
1607 } else {

--- 29 unchanged lines hidden (view full) ---

1637 case PPPOE_DEAD:
1638 case PPPOE_SNONE:
1639 case PPPOE_CONNECTED:
1640 printf("pppoe: sendpacket: unexpected state\n");
1641 break;
1642
1643 case PPPOE_NEWCONNECTED:
1644 /* send the PADS without a timeout - we're now connected */
1600 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1601 neg->timeout_handle = timeout(pppoe_ticker,
1602 hook, neg->timeout * hz);
1603 if ((neg->timeout <<= 1) > PPPOE_TIMEOUT_LIMIT) {
1604 if (sp->state == PPPOE_SREQ) {
1605 /* revert to SINIT mode */
1606 pppoe_start(sp);
1607 } else {

--- 29 unchanged lines hidden (view full) ---

1637 case PPPOE_DEAD:
1638 case PPPOE_SNONE:
1639 case PPPOE_CONNECTED:
1640 printf("pppoe: sendpacket: unexpected state\n");
1641 break;
1642
1643 case PPPOE_NEWCONNECTED:
1644 /* send the PADS without a timeout - we're now connected */
1645 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1645 m0 = m_copypacket(sp->neg->m, M_NOWAIT);
1646 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1647 break;
1648
1649 case PPPOE_PRIMED:
1650 /* No packet to send, but set up the timeout */
1651 neg->timeout_handle = timeout(pppoe_ticker,
1652 hook, PPPOE_OFFER_TIMEOUT * hz);
1653 break;
1654
1655 case PPPOE_SOFFER:
1656 /*
1657 * send the offer but if they don't respond
1658 * in PPPOE_OFFER_TIMEOUT seconds, forget about it.
1659 */
1646 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1647 break;
1648
1649 case PPPOE_PRIMED:
1650 /* No packet to send, but set up the timeout */
1651 neg->timeout_handle = timeout(pppoe_ticker,
1652 hook, PPPOE_OFFER_TIMEOUT * hz);
1653 break;
1654
1655 case PPPOE_SOFFER:
1656 /*
1657 * send the offer but if they don't respond
1658 * in PPPOE_OFFER_TIMEOUT seconds, forget about it.
1659 */
1660 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1660 m0 = m_copypacket(sp->neg->m, M_NOWAIT);
1661 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1662 neg->timeout_handle = timeout(pppoe_ticker,
1663 hook, PPPOE_OFFER_TIMEOUT * hz);
1664 break;
1665
1666 case PPPOE_SINIT:
1667 case PPPOE_SREQ:
1661 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1662 neg->timeout_handle = timeout(pppoe_ticker,
1663 hook, PPPOE_OFFER_TIMEOUT * hz);
1664 break;
1665
1666 case PPPOE_SINIT:
1667 case PPPOE_SREQ:
1668 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1668 m0 = m_copypacket(sp->neg->m, M_NOWAIT);
1669 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1670 neg->timeout_handle = timeout(pppoe_ticker, hook,
1671 (hz * PPPOE_INITIAL_TIMEOUT));
1672 neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
1673 break;
1674
1675 default:
1676 error = EINVAL;

--- 66 unchanged lines hidden ---
1669 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1670 neg->timeout_handle = timeout(pppoe_ticker, hook,
1671 (hz * PPPOE_INITIAL_TIMEOUT));
1672 neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
1673 break;
1674
1675 default:
1676 error = EINVAL;

--- 66 unchanged lines hidden ---