Deleted Added
full compact
ng_pppoe.c (227293) ng_pppoe.c (243882)
1/*
2 * ng_pppoe.c
3 */
4
5/*-
6 * Copyright (c) 1996-1999 Whistle Communications, Inc.
7 * All rights reserved.
8 *

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

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

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

32 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
36 * OF SUCH DAMAGE.
37 *
38 * Author: Julian Elischer <julian@freebsd.org>
39 *
40 * $FreeBSD: head/sys/netgraph/ng_pppoe.c 227293 2011-11-07 06:44:47Z ed $
40 * $FreeBSD: head/sys/netgraph/ng_pppoe.c 243882 2012-12-05 08:04:20Z glebius $
41 * $Whistle: ng_pppoe.c,v 1.10 1999/11/01 09:24:52 julian Exp $
42 */
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/kernel.h>
47#include <sys/ktr.h>
48#include <sys/mbuf.h>

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

455{
456 const priv_p privp = NG_NODE_PRIVATE(node);
457 sessp sp;
458 int error = 0;
459
460 LIST_FOREACH(sp, &privp->listeners, sessions) {
461 struct mbuf *m;
462
41 * $Whistle: ng_pppoe.c,v 1.10 1999/11/01 09:24:52 julian Exp $
42 */
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/kernel.h>
47#include <sys/ktr.h>
48#include <sys/mbuf.h>

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

455{
456 const priv_p privp = NG_NODE_PRIVATE(node);
457 sessp sp;
458 int error = 0;
459
460 LIST_FOREACH(sp, &privp->listeners, sessions) {
461 struct mbuf *m;
462
463 m = m_dup(m0, M_DONTWAIT);
463 m = m_dup(m0, M_NOWAIT);
464 if (m == NULL)
465 return (ENOMEM);
466 NG_SEND_DATA_ONLY(error, sp->hook, m);
467 if (error)
468 return (error);
469 }
470
471 return (0);

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

796 * Set up prototype header.
797 */
798 neg = malloc(sizeof(*neg), M_NETGRAPH_PPPOE,
799 M_NOWAIT | M_ZERO);
800
801 if (neg == NULL)
802 LEAVE(ENOMEM);
803
464 if (m == NULL)
465 return (ENOMEM);
466 NG_SEND_DATA_ONLY(error, sp->hook, m);
467 if (error)
468 return (error);
469 }
470
471 return (0);

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

796 * Set up prototype header.
797 */
798 neg = malloc(sizeof(*neg), M_NETGRAPH_PPPOE,
799 M_NOWAIT | M_ZERO);
800
801 if (neg == NULL)
802 LEAVE(ENOMEM);
803
804 neg->m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
804 neg->m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
805 if (neg->m == NULL) {
806 free(neg, M_NETGRAPH_PPPOE);
807 LEAVE(ENOBUFS);
808 }
809 neg->m->m_pkthdr.rcvif = NULL;
810 sp->neg = neg;
811 ng_callout_init(&neg->handle);
812 neg->m->m_len = sizeof(struct pppoe_full_hdr);

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

1073 insert_tag(sp, &neg->service.hdr);
1074 make_packet(sp);
1075 /*
1076 * Send packet and prepare to retransmit it after timeout.
1077 */
1078 ng_callout(&neg->handle, node, hook, PPPOE_INITIAL_TIMEOUT * hz,
1079 pppoe_ticker, NULL, 0);
1080 neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
805 if (neg->m == NULL) {
806 free(neg, M_NETGRAPH_PPPOE);
807 LEAVE(ENOBUFS);
808 }
809 neg->m->m_pkthdr.rcvif = NULL;
810 sp->neg = neg;
811 ng_callout_init(&neg->handle);
812 neg->m->m_len = sizeof(struct pppoe_full_hdr);

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

1073 insert_tag(sp, &neg->service.hdr);
1074 make_packet(sp);
1075 /*
1076 * Send packet and prepare to retransmit it after timeout.
1077 */
1078 ng_callout(&neg->handle, node, hook, PPPOE_INITIAL_TIMEOUT * hz,
1079 pppoe_ticker, NULL, 0);
1080 neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
1081 m0 = m_copypacket(neg->m, M_DONTWAIT);
1081 m0 = m_copypacket(neg->m, M_NOWAIT);
1082 NG_SEND_DATA_ONLY(error, privp->ethernet_hook, m0);
1083}
1084
1085static int
1086send_acname(sessp sp, const struct pppoe_tag *tag)
1087{
1088 int error, tlen;
1089 struct ng_mesg *msg;

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

1156 if (mtod(m, u_char *)[0] == 0xff &&
1157 mtod(m, u_char *)[1] == 0x03)
1158 m_adj(m, 2);
1159 }
1160 /*
1161 * Bang in a pre-made header, and set the length up
1162 * to be correct. Then send it to the ethernet driver.
1163 */
1082 NG_SEND_DATA_ONLY(error, privp->ethernet_hook, m0);
1083}
1084
1085static int
1086send_acname(sessp sp, const struct pppoe_tag *tag)
1087{
1088 int error, tlen;
1089 struct ng_mesg *msg;

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

1156 if (mtod(m, u_char *)[0] == 0xff &&
1157 mtod(m, u_char *)[1] == 0x03)
1158 m_adj(m, 2);
1159 }
1160 /*
1161 * Bang in a pre-made header, and set the length up
1162 * to be correct. Then send it to the ethernet driver.
1163 */
1164 M_PREPEND(m, sizeof(*wh), M_DONTWAIT);
1164 M_PREPEND(m, sizeof(*wh), M_NOWAIT);
1165 if (m == NULL)
1166 LEAVE(ENOBUFS);
1167
1168 wh = mtod(m, struct pppoe_full_hdr *);
1169 bcopy(&sp->pkt_hdr, wh, sizeof(*wh));
1170 wh->ph.length = htons(m->m_pkthdr.len - sizeof(*wh));
1171 NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m);
1172 privp->packets_out++;

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

1246 scan_tags(sp, ph);
1247 make_packet(sp);
1248 /*
1249 * Send the offer but if they don't respond
1250 * in PPPOE_OFFER_TIMEOUT seconds, forget about it.
1251 */
1252 ng_callout(&neg->handle, node, hook, PPPOE_OFFER_TIMEOUT * hz,
1253 pppoe_ticker, NULL, 0);
1165 if (m == NULL)
1166 LEAVE(ENOBUFS);
1167
1168 wh = mtod(m, struct pppoe_full_hdr *);
1169 bcopy(&sp->pkt_hdr, wh, sizeof(*wh));
1170 wh->ph.length = htons(m->m_pkthdr.len - sizeof(*wh));
1171 NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m);
1172 privp->packets_out++;

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

1246 scan_tags(sp, ph);
1247 make_packet(sp);
1248 /*
1249 * Send the offer but if they don't respond
1250 * in PPPOE_OFFER_TIMEOUT seconds, forget about it.
1251 */
1252 ng_callout(&neg->handle, node, hook, PPPOE_OFFER_TIMEOUT * hz,
1253 pppoe_ticker, NULL, 0);
1254 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1254 m0 = m_copypacket(sp->neg->m, M_NOWAIT);
1255 NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m0);
1256 privp->packets_out++;
1257 break;
1258 }
1259
1260 /*
1261 * Packets coming from the hook make no sense
1262 * to sessions in the rest of states. Throw them away.

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

1333 }
1334 if (m->m_len != m->m_pkthdr.len) {
1335 /*
1336 * It's not all in one piece.
1337 * We need to do extra work.
1338 * Put it into a cluster.
1339 */
1340 struct mbuf *n;
1255 NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m0);
1256 privp->packets_out++;
1257 break;
1258 }
1259
1260 /*
1261 * Packets coming from the hook make no sense
1262 * to sessions in the rest of states. Throw them away.

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

1333 }
1334 if (m->m_len != m->m_pkthdr.len) {
1335 /*
1336 * It's not all in one piece.
1337 * We need to do extra work.
1338 * Put it into a cluster.
1339 */
1340 struct mbuf *n;
1341 n = m_dup(m, M_DONTWAIT);
1341 n = m_dup(m, M_NOWAIT);
1342 m_freem(m);
1343 m = n;
1344 if (m) {
1345 /* just check we got a cluster */
1346 if (m->m_len != m->m_pkthdr.len) {
1347 m_freem(m);
1348 m = NULL;
1349 }

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

1467 insert_tag(sp, &neg->service.hdr); /* Service */
1468 scan_tags(sp, ph);
1469 make_packet(sp);
1470 sp->state = PPPOE_SREQ;
1471 ng_callout(&neg->handle, node, sp->hook,
1472 PPPOE_INITIAL_TIMEOUT * hz,
1473 pppoe_ticker, NULL, 0);
1474 neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
1342 m_freem(m);
1343 m = n;
1344 if (m) {
1345 /* just check we got a cluster */
1346 if (m->m_len != m->m_pkthdr.len) {
1347 m_freem(m);
1348 m = NULL;
1349 }

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

1467 insert_tag(sp, &neg->service.hdr); /* Service */
1468 scan_tags(sp, ph);
1469 make_packet(sp);
1470 sp->state = PPPOE_SREQ;
1471 ng_callout(&neg->handle, node, sp->hook,
1472 PPPOE_INITIAL_TIMEOUT * hz,
1473 pppoe_ticker, NULL, 0);
1474 neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
1475 m0 = m_copypacket(neg->m, M_DONTWAIT);
1475 m0 = m_copypacket(neg->m, M_NOWAIT);
1476 NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m0);
1477 break;
1478 case PADR_CODE:
1479 /*
1480 * We are a server:
1481 * Use the ac_cookie tag to find the
1482 * hook this is in response to.
1483 */

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

1525 if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
1526 insert_tag(sp, tag); /* return it */
1527 insert_tag(sp, utag); /* ac_cookie */
1528 scan_tags(sp, ph);
1529 make_packet(sp);
1530 sp->state = PPPOE_NEWCONNECTED;
1531
1532 /* Send the PADS without a timeout - we're now connected. */
1476 NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m0);
1477 break;
1478 case PADR_CODE:
1479 /*
1480 * We are a server:
1481 * Use the ac_cookie tag to find the
1482 * hook this is in response to.
1483 */

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

1525 if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
1526 insert_tag(sp, tag); /* return it */
1527 insert_tag(sp, utag); /* ac_cookie */
1528 scan_tags(sp, ph);
1529 make_packet(sp);
1530 sp->state = PPPOE_NEWCONNECTED;
1531
1532 /* Send the PADS without a timeout - we're now connected. */
1533 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1533 m0 = m_copypacket(sp->neg->m, M_NOWAIT);
1534 NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m0);
1535
1536 /*
1537 * Having sent the last Negotiation header,
1538 * Set up the stored packet header to be correct for
1539 * the actual session. But keep the negotialtion stuff
1540 * around in case we need to resend this last packet.
1541 * We'll discard it when we move from NEWCONNECTED

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

1731 * a session.
1732 */
1733 if ((privp->ethernet_hook)
1734 && ((sp->state == PPPOE_CONNECTED)
1735 || (sp->state == PPPOE_NEWCONNECTED))) {
1736 struct mbuf *m;
1737
1738 /* Generate a packet of that type. */
1534 NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m0);
1535
1536 /*
1537 * Having sent the last Negotiation header,
1538 * Set up the stored packet header to be correct for
1539 * the actual session. But keep the negotialtion stuff
1540 * around in case we need to resend this last packet.
1541 * We'll discard it when we move from NEWCONNECTED

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

1731 * a session.
1732 */
1733 if ((privp->ethernet_hook)
1734 && ((sp->state == PPPOE_CONNECTED)
1735 || (sp->state == PPPOE_NEWCONNECTED))) {
1736 struct mbuf *m;
1737
1738 /* Generate a packet of that type. */
1739 MGETHDR(m, M_DONTWAIT, MT_DATA);
1739 MGETHDR(m, M_NOWAIT, MT_DATA);
1740 if (m == NULL)
1741 log(LOG_NOTICE, "ng_pppoe[%x]: session out of "
1742 "mbufs\n", node->nd_ID);
1743 else {
1744 struct pppoe_full_hdr *wh;
1745 struct pppoe_tag *tag;
1746 int msglen = strlen(SIGNOFF);
1747 int error = 0;

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

1818 /*
1819 * Resend the last packet, using an exponential backoff.
1820 * After a period of time, stop growing the backoff,
1821 * And either leave it, or revert to the start.
1822 */
1823 case PPPOE_SINIT:
1824 case PPPOE_SREQ:
1825 /* Timeouts on these produce resends. */
1740 if (m == NULL)
1741 log(LOG_NOTICE, "ng_pppoe[%x]: session out of "
1742 "mbufs\n", node->nd_ID);
1743 else {
1744 struct pppoe_full_hdr *wh;
1745 struct pppoe_tag *tag;
1746 int msglen = strlen(SIGNOFF);
1747 int error = 0;

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

1818 /*
1819 * Resend the last packet, using an exponential backoff.
1820 * After a period of time, stop growing the backoff,
1821 * And either leave it, or revert to the start.
1822 */
1823 case PPPOE_SINIT:
1824 case PPPOE_SREQ:
1825 /* Timeouts on these produce resends. */
1826 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1826 m0 = m_copypacket(sp->neg->m, M_NOWAIT);
1827 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1828 ng_callout(&neg->handle, node, hook, neg->timeout * hz,
1829 pppoe_ticker, NULL, 0);
1830 if ((neg->timeout <<= 1) > PPPOE_TIMEOUT_LIMIT) {
1831 if (sp->state == PPPOE_SREQ) {
1832 /* Revert to SINIT mode. */
1833 pppoe_start(sp);
1834 } else {

--- 80 unchanged lines hidden ---
1827 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1828 ng_callout(&neg->handle, node, hook, neg->timeout * hz,
1829 pppoe_ticker, NULL, 0);
1830 if ((neg->timeout <<= 1) > PPPOE_TIMEOUT_LIMIT) {
1831 if (sp->state == PPPOE_SREQ) {
1832 /* Revert to SINIT mode. */
1833 pppoe_start(sp);
1834 } else {

--- 80 unchanged lines hidden ---