Deleted Added
full compact
sctp_output.c (284439) sctp_output.c (284633)
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/sctp_output.c 284439 2015-06-16 08:24:08Z tuexen $");
34__FBSDID("$FreeBSD: stable/10/sys/netinet/sctp_output.c 284633 2015-06-20 08:25:27Z tuexen $");
35
36#include <netinet/sctp_os.h>
37#include <sys/proc.h>
38#include <netinet/sctp_var.h>
39#include <netinet/sctp_sysctl.h>
40#include <netinet/sctp_header.h>
41#include <netinet/sctp_pcb.h>
42#include <netinet/sctputil.h>

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

3384 * use the same concept but instead only consider the bound
3385 * addresses. If the bound set is NOT assigned to the interface then
3386 * we must use rotation amongst the bound addresses..
3387 */
3388 if (ro->ro_rt == NULL) {
3389 /*
3390 * Need a route to cache.
3391 */
35
36#include <netinet/sctp_os.h>
37#include <sys/proc.h>
38#include <netinet/sctp_var.h>
39#include <netinet/sctp_sysctl.h>
40#include <netinet/sctp_header.h>
41#include <netinet/sctp_pcb.h>
42#include <netinet/sctputil.h>

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

3384 * use the same concept but instead only consider the bound
3385 * addresses. If the bound set is NOT assigned to the interface then
3386 * we must use rotation amongst the bound addresses..
3387 */
3388 if (ro->ro_rt == NULL) {
3389 /*
3390 * Need a route to cache.
3391 */
3392 SCTP_RTALLOC(ro, vrf_id);
3392 SCTP_RTALLOC(ro, vrf_id, inp->fibnum);
3393 }
3394 if (ro->ro_rt == NULL) {
3395 return (NULL);
3396 }
3397 fam = ro->ro_dst.sa_family;
3398 dest_is_priv = dest_is_loop = 0;
3399 /* Setup our scopes for the destination */
3400 switch (fam) {

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

4165 SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH);
4166 sctp_m_freem(m);
4167 return (EHOSTUNREACH);
4168 }
4169 ip->ip_src = _lsrc->address.sin.sin_addr;
4170 sctp_free_ifa(_lsrc);
4171 } else {
4172 ip->ip_src = over_addr->sin.sin_addr;
3393 }
3394 if (ro->ro_rt == NULL) {
3395 return (NULL);
3396 }
3397 fam = ro->ro_dst.sa_family;
3398 dest_is_priv = dest_is_loop = 0;
3399 /* Setup our scopes for the destination */
3400 switch (fam) {

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

4165 SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH);
4166 sctp_m_freem(m);
4167 return (EHOSTUNREACH);
4168 }
4169 ip->ip_src = _lsrc->address.sin.sin_addr;
4170 sctp_free_ifa(_lsrc);
4171 } else {
4172 ip->ip_src = over_addr->sin.sin_addr;
4173 SCTP_RTALLOC(ro, vrf_id);
4173 SCTP_RTALLOC(ro, vrf_id, inp->fibnum);
4174 }
4175 }
4176 if (port) {
4177 if (htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)) == 0) {
4178 sctp_handle_no_route(stcb, net, so_locked);
4179 SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH);
4180 sctp_m_freem(m);
4181 return (EHOSTUNREACH);

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

4479 SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH);
4480 sctp_m_freem(m);
4481 return (EHOSTUNREACH);
4482 }
4483 lsa6->sin6_addr = _lsrc->address.sin6.sin6_addr;
4484 sctp_free_ifa(_lsrc);
4485 } else {
4486 lsa6->sin6_addr = over_addr->sin6.sin6_addr;
4174 }
4175 }
4176 if (port) {
4177 if (htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)) == 0) {
4178 sctp_handle_no_route(stcb, net, so_locked);
4179 SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH);
4180 sctp_m_freem(m);
4181 return (EHOSTUNREACH);

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

4479 SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EHOSTUNREACH);
4480 sctp_m_freem(m);
4481 return (EHOSTUNREACH);
4482 }
4483 lsa6->sin6_addr = _lsrc->address.sin6.sin6_addr;
4484 sctp_free_ifa(_lsrc);
4485 } else {
4486 lsa6->sin6_addr = over_addr->sin6.sin6_addr;
4487 SCTP_RTALLOC(ro, vrf_id);
4487 SCTP_RTALLOC(ro, vrf_id, inp->fibnum);
4488 }
4489 (void)sa6_recoverscope(sin6);
4490 }
4491 lsa6->sin6_port = inp->sctp_lport;
4492
4493 if (ro->ro_rt == NULL) {
4494 /*
4495 * src addr selection failed to find a route

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

5506 /*
5507 * Send a ABORT, we don't add the new address error clause
5508 * though we even set the T bit and copy in the 0 tag.. this
5509 * looks no different than if no listener was present.
5510 */
5511 op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
5512 "Address added");
5513 sctp_send_abort(init_pkt, iphlen, src, dst, sh, 0, op_err,
4488 }
4489 (void)sa6_recoverscope(sin6);
4490 }
4491 lsa6->sin6_port = inp->sctp_lport;
4492
4493 if (ro->ro_rt == NULL) {
4494 /*
4495 * src addr selection failed to find a route

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

5506 /*
5507 * Send a ABORT, we don't add the new address error clause
5508 * though we even set the T bit and copy in the 0 tag.. this
5509 * looks no different than if no listener was present.
5510 */
5511 op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
5512 "Address added");
5513 sctp_send_abort(init_pkt, iphlen, src, dst, sh, 0, op_err,
5514 mflowtype, mflowid,
5514 mflowtype, mflowid, inp->fibnum,
5515 vrf_id, port);
5516 return;
5517 }
5518 abort_flag = 0;
5519 op_err = sctp_arethere_unrecognized_parameters(init_pkt,
5520 (offset + sizeof(struct sctp_init_chunk)),
5521 &abort_flag, (struct sctp_chunkhdr *)init_chk, &nat_friendly);
5522 if (abort_flag) {
5523do_a_abort:
5524 if (op_err == NULL) {
5525 char msg[SCTP_DIAG_INFO_LEN];
5526
5527 snprintf(msg, sizeof(msg), "%s:%d at %s\n", __FILE__, __LINE__, __FUNCTION__);
5528 op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
5529 msg);
5530 }
5531 sctp_send_abort(init_pkt, iphlen, src, dst, sh,
5532 init_chk->init.initiate_tag, op_err,
5515 vrf_id, port);
5516 return;
5517 }
5518 abort_flag = 0;
5519 op_err = sctp_arethere_unrecognized_parameters(init_pkt,
5520 (offset + sizeof(struct sctp_init_chunk)),
5521 &abort_flag, (struct sctp_chunkhdr *)init_chk, &nat_friendly);
5522 if (abort_flag) {
5523do_a_abort:
5524 if (op_err == NULL) {
5525 char msg[SCTP_DIAG_INFO_LEN];
5526
5527 snprintf(msg, sizeof(msg), "%s:%d at %s\n", __FILE__, __LINE__, __FUNCTION__);
5528 op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
5529 msg);
5530 }
5531 sctp_send_abort(init_pkt, iphlen, src, dst, sh,
5532 init_chk->init.initiate_tag, op_err,
5533 mflowtype, mflowid,
5533 mflowtype, mflowid, inp->fibnum,
5534 vrf_id, port);
5535 return;
5536 }
5537 m = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
5538 if (m == NULL) {
5539 /* No memory, INIT timer will re-attempt. */
5540 if (op_err)
5541 sctp_m_freem(op_err);

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

10850 SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks);
10851 return;
10852}
10853
10854static void
10855sctp_send_resp_msg(struct sockaddr *src, struct sockaddr *dst,
10856 struct sctphdr *sh, uint32_t vtag,
10857 uint8_t type, struct mbuf *cause,
5534 vrf_id, port);
5535 return;
5536 }
5537 m = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
5538 if (m == NULL) {
5539 /* No memory, INIT timer will re-attempt. */
5540 if (op_err)
5541 sctp_m_freem(op_err);

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

10850 SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks);
10851 return;
10852}
10853
10854static void
10855sctp_send_resp_msg(struct sockaddr *src, struct sockaddr *dst,
10856 struct sctphdr *sh, uint32_t vtag,
10857 uint8_t type, struct mbuf *cause,
10858 uint8_t mflowtype, uint32_t mflowid,
10858 uint8_t mflowtype, uint32_t mflowid, uint16_t fibnum,
10859 uint32_t vrf_id, uint16_t port)
10860{
10861 struct mbuf *o_pak;
10862 struct mbuf *mout;
10863 struct sctphdr *shout;
10864 struct sctp_chunkhdr *ch;
10865
10866#if defined(INET) || defined(INET6)

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

10930 if (cause) {
10931 sctp_m_freem(cause);
10932 }
10933 return;
10934 }
10935 SCTP_BUF_RESV_UF(mout, max_linkhdr);
10936 SCTP_BUF_LEN(mout) = len;
10937 SCTP_BUF_NEXT(mout) = cause;
10859 uint32_t vrf_id, uint16_t port)
10860{
10861 struct mbuf *o_pak;
10862 struct mbuf *mout;
10863 struct sctphdr *shout;
10864 struct sctp_chunkhdr *ch;
10865
10866#if defined(INET) || defined(INET6)

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

10930 if (cause) {
10931 sctp_m_freem(cause);
10932 }
10933 return;
10934 }
10935 SCTP_BUF_RESV_UF(mout, max_linkhdr);
10936 SCTP_BUF_LEN(mout) = len;
10937 SCTP_BUF_NEXT(mout) = cause;
10938 M_SETFIB(mout, fibnum);
10938 mout->m_pkthdr.flowid = mflowid;
10939 M_HASHTYPE_SET(mout, mflowtype);
10940#ifdef INET
10941 ip = NULL;
10942#endif
10943#ifdef INET6
10944 ip6 = NULL;
10945#endif

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

11117 SCTP_STAT_INCR_COUNTER64(sctps_outpackets);
11118 SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks);
11119 return;
11120}
11121
11122void
11123sctp_send_shutdown_complete2(struct sockaddr *src, struct sockaddr *dst,
11124 struct sctphdr *sh,
10939 mout->m_pkthdr.flowid = mflowid;
10940 M_HASHTYPE_SET(mout, mflowtype);
10941#ifdef INET
10942 ip = NULL;
10943#endif
10944#ifdef INET6
10945 ip6 = NULL;
10946#endif

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

11118 SCTP_STAT_INCR_COUNTER64(sctps_outpackets);
11119 SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks);
11120 return;
11121}
11122
11123void
11124sctp_send_shutdown_complete2(struct sockaddr *src, struct sockaddr *dst,
11125 struct sctphdr *sh,
11125 uint8_t mflowtype, uint32_t mflowid,
11126 uint8_t mflowtype, uint32_t mflowid, uint16_t fibnum,
11126 uint32_t vrf_id, uint16_t port)
11127{
11128 sctp_send_resp_msg(src, dst, sh, 0, SCTP_SHUTDOWN_COMPLETE, NULL,
11127 uint32_t vrf_id, uint16_t port)
11128{
11129 sctp_send_resp_msg(src, dst, sh, 0, SCTP_SHUTDOWN_COMPLETE, NULL,
11129 mflowtype, mflowid,
11130 mflowtype, mflowid, fibnum,
11130 vrf_id, port);
11131}
11132
11133void
11134sctp_send_hb(struct sctp_tcb *stcb, struct sctp_nets *net, int so_locked
11135#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
11136 SCTP_UNUSED
11137#endif

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

11940 asoc->ctrl_queue_cnt++;
11941 sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, stcb->sctp_ep, stcb, chk->whoTo);
11942 return (0);
11943}
11944
11945void
11946sctp_send_abort(struct mbuf *m, int iphlen, struct sockaddr *src, struct sockaddr *dst,
11947 struct sctphdr *sh, uint32_t vtag, struct mbuf *cause,
11131 vrf_id, port);
11132}
11133
11134void
11135sctp_send_hb(struct sctp_tcb *stcb, struct sctp_nets *net, int so_locked
11136#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
11137 SCTP_UNUSED
11138#endif

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

11941 asoc->ctrl_queue_cnt++;
11942 sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, stcb->sctp_ep, stcb, chk->whoTo);
11943 return (0);
11944}
11945
11946void
11947sctp_send_abort(struct mbuf *m, int iphlen, struct sockaddr *src, struct sockaddr *dst,
11948 struct sctphdr *sh, uint32_t vtag, struct mbuf *cause,
11948 uint8_t mflowtype, uint32_t mflowid,
11949 uint8_t mflowtype, uint32_t mflowid, uint16_t fibnum,
11949 uint32_t vrf_id, uint16_t port)
11950{
11951 /* Don't respond to an ABORT with an ABORT. */
11952 if (sctp_is_there_an_abort_here(m, iphlen, &vtag)) {
11953 if (cause)
11954 sctp_m_freem(cause);
11955 return;
11956 }
11957 sctp_send_resp_msg(src, dst, sh, vtag, SCTP_ABORT_ASSOCIATION, cause,
11950 uint32_t vrf_id, uint16_t port)
11951{
11952 /* Don't respond to an ABORT with an ABORT. */
11953 if (sctp_is_there_an_abort_here(m, iphlen, &vtag)) {
11954 if (cause)
11955 sctp_m_freem(cause);
11956 return;
11957 }
11958 sctp_send_resp_msg(src, dst, sh, vtag, SCTP_ABORT_ASSOCIATION, cause,
11958 mflowtype, mflowid,
11959 mflowtype, mflowid, fibnum,
11959 vrf_id, port);
11960 return;
11961}
11962
11963void
11964sctp_send_operr_to(struct sockaddr *src, struct sockaddr *dst,
11965 struct sctphdr *sh, uint32_t vtag, struct mbuf *cause,
11960 vrf_id, port);
11961 return;
11962}
11963
11964void
11965sctp_send_operr_to(struct sockaddr *src, struct sockaddr *dst,
11966 struct sctphdr *sh, uint32_t vtag, struct mbuf *cause,
11966 uint8_t mflowtype, uint32_t mflowid,
11967 uint8_t mflowtype, uint32_t mflowid, uint16_t fibnum,
11967 uint32_t vrf_id, uint16_t port)
11968{
11969 sctp_send_resp_msg(src, dst, sh, vtag, SCTP_OPERATION_ERROR, cause,
11968 uint32_t vrf_id, uint16_t port)
11969{
11970 sctp_send_resp_msg(src, dst, sh, vtag, SCTP_OPERATION_ERROR, cause,
11970 mflowtype, mflowid,
11971 mflowtype, mflowid, fibnum,
11971 vrf_id, port);
11972 return;
11973}
11974
11975static struct mbuf *
11976sctp_copy_resume(struct uio *uio,
11977 int max_send_len,
11978 int user_marks_eor,

--- 1496 unchanged lines hidden ---
11972 vrf_id, port);
11973 return;
11974}
11975
11976static struct mbuf *
11977sctp_copy_resume(struct uio *uio,
11978 int max_send_len,
11979 int user_marks_eor,

--- 1496 unchanged lines hidden ---