sctputil.c (179783) | sctputil.c (180387) |
---|---|
1/*- 2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * a) Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. --- 17 unchanged lines hidden (view full) --- 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 * THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31/* $KAME: sctputil.c,v 1.37 2005/03/07 23:26:09 itojun Exp $ */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * a) Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. --- 17 unchanged lines hidden (view full) --- 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 * THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31/* $KAME: sctputil.c,v 1.37 2005/03/07 23:26:09 itojun Exp $ */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/netinet/sctputil.c 179783 2008-06-14 07:58:05Z rrs $"); | 34__FBSDID("$FreeBSD: head/sys/netinet/sctputil.c 180387 2008-07-09 16:45:30Z rrs $"); |
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 | 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> | |
43#endif 44#include <netinet/sctp_header.h> 45#include <netinet/sctp_output.h> 46#include <netinet/sctp_uio.h> 47#include <netinet/sctp_timer.h> 48#include <netinet/sctp_crc32.h> 49#include <netinet/sctp_indata.h>/* for sctp_deliver_data() */ 50#include <netinet/sctp_auth.h> --- 3042 unchanged lines hidden (view full) --- 3093static void 3094sctp_notify_send_failed(struct sctp_tcb *stcb, uint32_t error, 3095 struct sctp_tmit_chunk *chk, int so_locked 3096#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 3097 SCTP_UNUSED 3098#endif 3099) 3100{ | 42#endif 43#include <netinet/sctp_header.h> 44#include <netinet/sctp_output.h> 45#include <netinet/sctp_uio.h> 46#include <netinet/sctp_timer.h> 47#include <netinet/sctp_crc32.h> 48#include <netinet/sctp_indata.h>/* for sctp_deliver_data() */ 49#include <netinet/sctp_auth.h> --- 3042 unchanged lines hidden (view full) --- 3092static void 3093sctp_notify_send_failed(struct sctp_tcb *stcb, uint32_t error, 3094 struct sctp_tmit_chunk *chk, int so_locked 3095#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 3096 SCTP_UNUSED 3097#endif 3098) 3099{ |
3101 struct mbuf *m_notify; | 3100 struct mbuf *m_notify, *tt; |
3102 struct sctp_send_failed *ssf; 3103 struct sctp_queued_to_read *control; 3104 int length; 3105 3106 if ((stcb == NULL) || (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))) 3107 /* event not enabled */ 3108 return; 3109 | 3101 struct sctp_send_failed *ssf; 3102 struct sctp_queued_to_read *control; 3103 int length; 3104 3105 if ((stcb == NULL) || (sctp_is_feature_off(stcb->sctp_ep, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))) 3106 /* event not enabled */ 3107 return; 3108 |
3110 length = sizeof(struct sctp_send_failed) + chk->send_size; | |
3111 m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_send_failed), 0, M_DONTWAIT, 1, MT_DATA); 3112 if (m_notify == NULL) 3113 /* no space left */ 3114 return; | 3109 m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_send_failed), 0, M_DONTWAIT, 1, MT_DATA); 3110 if (m_notify == NULL) 3111 /* no space left */ 3112 return; |
3113 length = sizeof(struct sctp_send_failed) + chk->send_size; 3114 length -= sizeof(struct sctp_data_chunk); |
|
3115 SCTP_BUF_LEN(m_notify) = 0; 3116 ssf = mtod(m_notify, struct sctp_send_failed *); 3117 ssf->ssf_type = SCTP_SEND_FAILED; 3118 if (error == SCTP_NOTIFY_DATAGRAM_UNSENT) 3119 ssf->ssf_flags = SCTP_DATA_UNSENT; 3120 else 3121 ssf->ssf_flags = SCTP_DATA_SENT; 3122 ssf->ssf_length = length; 3123 ssf->ssf_error = error; 3124 /* not exactly what the user sent in, but should be close :) */ 3125 bzero(&ssf->ssf_info, sizeof(ssf->ssf_info)); 3126 ssf->ssf_info.sinfo_stream = chk->rec.data.stream_number; 3127 ssf->ssf_info.sinfo_ssn = chk->rec.data.stream_seq; 3128 ssf->ssf_info.sinfo_flags = chk->rec.data.rcv_flags; 3129 ssf->ssf_info.sinfo_ppid = chk->rec.data.payloadtype; 3130 ssf->ssf_info.sinfo_context = chk->rec.data.context; 3131 ssf->ssf_info.sinfo_assoc_id = sctp_get_associd(stcb); 3132 ssf->ssf_assoc_id = sctp_get_associd(stcb); | 3115 SCTP_BUF_LEN(m_notify) = 0; 3116 ssf = mtod(m_notify, struct sctp_send_failed *); 3117 ssf->ssf_type = SCTP_SEND_FAILED; 3118 if (error == SCTP_NOTIFY_DATAGRAM_UNSENT) 3119 ssf->ssf_flags = SCTP_DATA_UNSENT; 3120 else 3121 ssf->ssf_flags = SCTP_DATA_SENT; 3122 ssf->ssf_length = length; 3123 ssf->ssf_error = error; 3124 /* not exactly what the user sent in, but should be close :) */ 3125 bzero(&ssf->ssf_info, sizeof(ssf->ssf_info)); 3126 ssf->ssf_info.sinfo_stream = chk->rec.data.stream_number; 3127 ssf->ssf_info.sinfo_ssn = chk->rec.data.stream_seq; 3128 ssf->ssf_info.sinfo_flags = chk->rec.data.rcv_flags; 3129 ssf->ssf_info.sinfo_ppid = chk->rec.data.payloadtype; 3130 ssf->ssf_info.sinfo_context = chk->rec.data.context; 3131 ssf->ssf_info.sinfo_assoc_id = sctp_get_associd(stcb); 3132 ssf->ssf_assoc_id = sctp_get_associd(stcb); |
3133 3134 /* Take off the chunk header */ 3135 m_adj(chk->data, sizeof(struct sctp_data_chunk)); 3136 3137 /* trim out any 0 len mbufs */ 3138 while (SCTP_BUF_LEN(chk->data) == 0) { 3139 tt = chk->data; 3140 chk->data = SCTP_BUF_NEXT(tt); 3141 SCTP_BUF_NEXT(tt) = NULL; 3142 sctp_m_freem(tt); 3143 } 3144 |
|
3133 SCTP_BUF_NEXT(m_notify) = chk->data; 3134 SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_send_failed); 3135 3136 /* Steal off the mbuf */ 3137 chk->data = NULL; 3138 /* 3139 * For this case, we check the actual socket buffer, since the assoc 3140 * is going away we don't want to overfill the socket buffer for a --- 49 unchanged lines hidden (view full) --- 3190 else 3191 ssf->ssf_flags = SCTP_DATA_SENT; 3192 ssf->ssf_length = length; 3193 ssf->ssf_error = error; 3194 /* not exactly what the user sent in, but should be close :) */ 3195 bzero(&ssf->ssf_info, sizeof(ssf->ssf_info)); 3196 ssf->ssf_info.sinfo_stream = sp->stream; 3197 ssf->ssf_info.sinfo_ssn = sp->strseq; | 3145 SCTP_BUF_NEXT(m_notify) = chk->data; 3146 SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_send_failed); 3147 3148 /* Steal off the mbuf */ 3149 chk->data = NULL; 3150 /* 3151 * For this case, we check the actual socket buffer, since the assoc 3152 * is going away we don't want to overfill the socket buffer for a --- 49 unchanged lines hidden (view full) --- 3202 else 3203 ssf->ssf_flags = SCTP_DATA_SENT; 3204 ssf->ssf_length = length; 3205 ssf->ssf_error = error; 3206 /* not exactly what the user sent in, but should be close :) */ 3207 bzero(&ssf->ssf_info, sizeof(ssf->ssf_info)); 3208 ssf->ssf_info.sinfo_stream = sp->stream; 3209 ssf->ssf_info.sinfo_ssn = sp->strseq; |
3198 ssf->ssf_info.sinfo_flags = sp->sinfo_flags; | 3210 if (sp->some_taken) { 3211 ssf->ssf_info.sinfo_flags = SCTP_DATA_LAST_FRAG; 3212 } else { 3213 ssf->ssf_info.sinfo_flags = SCTP_DATA_NOT_FRAG; 3214 } |
3199 ssf->ssf_info.sinfo_ppid = sp->ppid; 3200 ssf->ssf_info.sinfo_context = sp->context; 3201 ssf->ssf_info.sinfo_assoc_id = sctp_get_associd(stcb); 3202 ssf->ssf_assoc_id = sctp_get_associd(stcb); 3203 SCTP_BUF_NEXT(m_notify) = sp->data; 3204 SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_send_failed); 3205 3206 /* Steal off the mbuf */ --- 2255 unchanged lines hidden (view full) --- 5462 ((size_t)fromlen >= sizeof(struct sockaddr_in6))) { 5463 struct sockaddr_in *sin; 5464 struct sockaddr_in6 sin6; 5465 5466 sin = (struct sockaddr_in *)to; 5467 bzero(&sin6, sizeof(sin6)); 5468 sin6.sin6_family = AF_INET6; 5469 sin6.sin6_len = sizeof(struct sockaddr_in6); | 3215 ssf->ssf_info.sinfo_ppid = sp->ppid; 3216 ssf->ssf_info.sinfo_context = sp->context; 3217 ssf->ssf_info.sinfo_assoc_id = sctp_get_associd(stcb); 3218 ssf->ssf_assoc_id = sctp_get_associd(stcb); 3219 SCTP_BUF_NEXT(m_notify) = sp->data; 3220 SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_send_failed); 3221 3222 /* Steal off the mbuf */ --- 2255 unchanged lines hidden (view full) --- 5478 ((size_t)fromlen >= sizeof(struct sockaddr_in6))) { 5479 struct sockaddr_in *sin; 5480 struct sockaddr_in6 sin6; 5481 5482 sin = (struct sockaddr_in *)to; 5483 bzero(&sin6, sizeof(sin6)); 5484 sin6.sin6_family = AF_INET6; 5485 sin6.sin6_len = sizeof(struct sockaddr_in6); |
5470 sin6.sin6_addr.s6_addr32[2] = ntohl(0x0000ffff); | 5486 sin6.sin6_addr.s6_addr16[2] = 0xffff; |
5471 bcopy(&sin->sin_addr, | 5487 bcopy(&sin->sin_addr, |
5472 &sin6.sin6_addr.s6_addr32[3], 5473 sizeof(sin6.sin6_addr.s6_addr32[3])); | 5488 &sin6.sin6_addr.s6_addr16[3], 5489 sizeof(sin6.sin6_addr.s6_addr16[3])); |
5474 sin6.sin6_port = sin->sin_port; 5475 memcpy(from, (caddr_t)&sin6, sizeof(sin6)); 5476 } 5477#endif 5478#if defined(INET6) 5479 { 5480 struct sockaddr_in6 lsa6, *to6; 5481 --- 513 unchanged lines hidden (view full) --- 5995 (struct sctp_inpcb *)NULL, 5996 (struct sctp_tcb *)NULL, 5997 (struct sctp_nets *)NULL); 5998 SCTP_IPI_ITERATOR_WQ_UNLOCK(); 5999 return (0); 6000} 6001 6002 | 5490 sin6.sin6_port = sin->sin_port; 5491 memcpy(from, (caddr_t)&sin6, sizeof(sin6)); 5492 } 5493#endif 5494#if defined(INET6) 5495 { 5496 struct sockaddr_in6 lsa6, *to6; 5497 --- 513 unchanged lines hidden (view full) --- 6011 (struct sctp_inpcb *)NULL, 6012 (struct sctp_tcb *)NULL, 6013 (struct sctp_nets *)NULL); 6014 SCTP_IPI_ITERATOR_WQ_UNLOCK(); 6015 return (0); 6016} 6017 6018 |
6003 6004 | |
6005int 6006sctp_soreceive(struct socket *so, 6007 struct sockaddr **psa, 6008 struct uio *uio, 6009 struct mbuf **mp0, 6010 struct mbuf **controlp, 6011 int *flagsp) 6012{ --- 238 unchanged lines hidden (view full) --- 6251 6252 /* see if we're bound all already! */ 6253 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 6254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); 6255 *error = EINVAL; 6256 return; 6257 } 6258 addr_touse = sa; | 6019int 6020sctp_soreceive(struct socket *so, 6021 struct sockaddr **psa, 6022 struct uio *uio, 6023 struct mbuf **mp0, 6024 struct mbuf **controlp, 6025 int *flagsp) 6026{ --- 238 unchanged lines hidden (view full) --- 6265 6266 /* see if we're bound all already! */ 6267 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 6268 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); 6269 *error = EINVAL; 6270 return; 6271 } 6272 addr_touse = sa; |
6259#if defined(INET6) | 6273#if defined(INET6) && !defined(__Userspace__) /* TODO port in6_sin6_2_sin */ |
6260 if (sa->sa_family == AF_INET6) { 6261 struct sockaddr_in6 *sin6; 6262 6263 if (sa->sa_len != sizeof(struct sockaddr_in6)) { 6264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); 6265 *error = EINVAL; 6266 return; 6267 } --- 109 unchanged lines hidden (view full) --- 6377 6378 /* see if we're bound all already! */ 6379 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 6380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); 6381 *error = EINVAL; 6382 return; 6383 } 6384 addr_touse = sa; | 6274 if (sa->sa_family == AF_INET6) { 6275 struct sockaddr_in6 *sin6; 6276 6277 if (sa->sa_len != sizeof(struct sockaddr_in6)) { 6278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); 6279 *error = EINVAL; 6280 return; 6281 } --- 109 unchanged lines hidden (view full) --- 6391 6392 /* see if we're bound all already! */ 6393 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 6394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); 6395 *error = EINVAL; 6396 return; 6397 } 6398 addr_touse = sa; |
6385#if defined(INET6) | 6399#if defined(INET6) && !defined(__Userspace__) /* TODO port in6_sin6_2_sin */ |
6386 if (sa->sa_family == AF_INET6) { 6387 struct sockaddr_in6 *sin6; 6388 6389 if (sa->sa_len != sizeof(struct sockaddr_in6)) { 6390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); 6391 *error = EINVAL; 6392 return; 6393 } --- 232 unchanged lines hidden --- | 6400 if (sa->sa_family == AF_INET6) { 6401 struct sockaddr_in6 *sin6; 6402 6403 if (sa->sa_len != sizeof(struct sockaddr_in6)) { 6404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); 6405 *error = EINVAL; 6406 return; 6407 } --- 232 unchanged lines hidden --- |