Deleted Added
full compact
sctputil.c (270353) sctputil.c (270354)
1/*-
2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *

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

26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *

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

26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: stable/10/sys/netinet/sctputil.c 270353 2014-08-22 19:46:22Z tuexen $");
34__FBSDID("$FreeBSD: stable/10/sys/netinet/sctputil.c 270354 2014-08-22 19:49:43Z tuexen $");
35
36#include <netinet/sctp_os.h>
37#include <netinet/sctp_pcb.h>
38#include <netinet/sctputil.h>
39#include <netinet/sctp_var.h>
40#include <netinet/sctp_sysctl.h>
41#ifdef INET6
42#include <netinet6/sctp6_var.h>

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

2511 int pull_limit)
2512{
2513 /* This just provides a typed signature to Peter's Pull routine */
2514 return ((struct sctp_paramhdr *)sctp_m_getptr(m, offset, pull_limit,
2515 (uint8_t *) pull));
2516}
2517
2518
35
36#include <netinet/sctp_os.h>
37#include <netinet/sctp_pcb.h>
38#include <netinet/sctputil.h>
39#include <netinet/sctp_var.h>
40#include <netinet/sctp_sysctl.h>
41#ifdef INET6
42#include <netinet6/sctp6_var.h>

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

2511 int pull_limit)
2512{
2513 /* This just provides a typed signature to Peter's Pull routine */
2514 return ((struct sctp_paramhdr *)sctp_m_getptr(m, offset, pull_limit,
2515 (uint8_t *) pull));
2516}
2517
2518
2519int
2519struct mbuf *
2520sctp_add_pad_tombuf(struct mbuf *m, int padlen)
2521{
2520sctp_add_pad_tombuf(struct mbuf *m, int padlen)
2521{
2522 /*
2523 * add padlen bytes of 0 filled padding to the end of the mbuf. If
2524 * padlen is > 3 this routine will fail.
2525 */
2526 uint8_t *dp;
2527 int i;
2522 struct mbuf *m_last;
2523 caddr_t dp;
2528
2529 if (padlen > 3) {
2524
2525 if (padlen > 3) {
2530 SCTP_LTRACE_ERR_RET_PKT(m, NULL, NULL, NULL, SCTP_FROM_SCTPUTIL, ENOBUFS);
2531 return (ENOBUFS);
2526 return (NULL);
2532 }
2533 if (padlen <= M_TRAILINGSPACE(m)) {
2534 /*
2535 * The easy way. We hope the majority of the time we hit
2536 * here :)
2537 */
2527 }
2528 if (padlen <= M_TRAILINGSPACE(m)) {
2529 /*
2530 * The easy way. We hope the majority of the time we hit
2531 * here :)
2532 */
2538 dp = (uint8_t *) (mtod(m, caddr_t)+SCTP_BUF_LEN(m));
2539 SCTP_BUF_LEN(m) += padlen;
2533 m_last = m;
2540 } else {
2534 } else {
2541 /* Hard way we must grow the mbuf */
2542 struct mbuf *tmp;
2543
2544 tmp = sctp_get_mbuf_for_msg(padlen, 0, M_NOWAIT, 1, MT_DATA);
2545 if (tmp == NULL) {
2546 /* Out of space GAK! we are in big trouble. */
2547 SCTP_LTRACE_ERR_RET_PKT(m, NULL, NULL, NULL, SCTP_FROM_SCTPUTIL, ENOBUFS);
2548 return (ENOBUFS);
2535 /* Hard way we must grow the mbuf chain */
2536 m_last = sctp_get_mbuf_for_msg(padlen, 0, M_NOWAIT, 1, MT_DATA);
2537 if (m_last == NULL) {
2538 return (NULL);
2549 }
2539 }
2550 /* setup and insert in middle */
2551 SCTP_BUF_LEN(tmp) = padlen;
2552 SCTP_BUF_NEXT(tmp) = NULL;
2553 SCTP_BUF_NEXT(m) = tmp;
2554 dp = mtod(tmp, uint8_t *);
2540 SCTP_BUF_LEN(m_last) = 0;
2541 SCTP_BUF_NEXT(m_last) = NULL;
2542 SCTP_BUF_NEXT(m) = m_last;
2555 }
2543 }
2556 /* zero out the pad */
2557 for (i = 0; i < padlen; i++) {
2558 *dp = 0;
2559 dp++;
2560 }
2561 return (0);
2544 dp = mtod(m_last, caddr_t)+SCTP_BUF_LEN(m_last);
2545 SCTP_BUF_LEN(m_last) += padlen;
2546 memset(dp, 0, padlen);
2547 return (m_last);
2562}
2563
2548}
2549
2564int
2550struct mbuf *
2565sctp_pad_lastmbuf(struct mbuf *m, int padval, struct mbuf *last_mbuf)
2566{
2567 /* find the last mbuf in chain and pad it */
2568 struct mbuf *m_at;
2569
2551sctp_pad_lastmbuf(struct mbuf *m, int padval, struct mbuf *last_mbuf)
2552{
2553 /* find the last mbuf in chain and pad it */
2554 struct mbuf *m_at;
2555
2570 if (last_mbuf) {
2556 if (last_mbuf != NULL) {
2571 return (sctp_add_pad_tombuf(last_mbuf, padval));
2572 } else {
2573 for (m_at = m; m_at; m_at = SCTP_BUF_NEXT(m_at)) {
2574 if (SCTP_BUF_NEXT(m_at) == NULL) {
2575 return (sctp_add_pad_tombuf(m_at, padval));
2576 }
2577 }
2578 }
2557 return (sctp_add_pad_tombuf(last_mbuf, padval));
2558 } else {
2559 for (m_at = m; m_at; m_at = SCTP_BUF_NEXT(m_at)) {
2560 if (SCTP_BUF_NEXT(m_at) == NULL) {
2561 return (sctp_add_pad_tombuf(m_at, padval));
2562 }
2563 }
2564 }
2579 SCTP_LTRACE_ERR_RET_PKT(m, NULL, NULL, NULL, SCTP_FROM_SCTPUTIL, EFAULT);
2580 return (EFAULT);
2565 return (NULL);
2581}
2582
2583static void
2584sctp_notify_assoc_change(uint16_t state, struct sctp_tcb *stcb,
2585 uint16_t error, struct sctp_abort_chunk *abort, uint8_t from_peer, int so_locked
2586#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
2587 SCTP_UNUSED
2588#endif

--- 4401 unchanged lines hidden ---
2566}
2567
2568static void
2569sctp_notify_assoc_change(uint16_t state, struct sctp_tcb *stcb,
2570 uint16_t error, struct sctp_abort_chunk *abort, uint8_t from_peer, int so_locked
2571#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
2572 SCTP_UNUSED
2573#endif

--- 4401 unchanged lines hidden ---