sctp_bsd_addr.c (178251) | sctp_bsd_addr.c (179783) |
---|---|
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: sctp_output.c,v 1.46 2005/03/06 16:04:17 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: sctp_output.c,v 1.46 2005/03/06 16:04:17 itojun Exp $ */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.c 178251 2008-04-16 17:24:18Z rrs $"); | 34__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.c 179783 2008-06-14 07:58:05Z rrs $"); |
35 36#include <netinet/sctp_os.h> 37#include <netinet/sctp_var.h> 38#include <netinet/sctp_pcb.h> 39#include <netinet/sctp_header.h> 40#include <netinet/sctputil.h> 41#include <netinet/sctp_output.h> 42#include <netinet/sctp_bsd_addr.h> 43#include <netinet/sctp_uio.h> 44#include <netinet/sctputil.h> 45#include <netinet/sctp_timer.h> 46#include <netinet/sctp_asconf.h> 47#include <netinet/sctp_sysctl.h> 48#include <netinet/sctp_indata.h> 49#include <sys/unistd.h> 50 | 35 36#include <netinet/sctp_os.h> 37#include <netinet/sctp_var.h> 38#include <netinet/sctp_pcb.h> 39#include <netinet/sctp_header.h> 40#include <netinet/sctputil.h> 41#include <netinet/sctp_output.h> 42#include <netinet/sctp_bsd_addr.h> 43#include <netinet/sctp_uio.h> 44#include <netinet/sctputil.h> 45#include <netinet/sctp_timer.h> 46#include <netinet/sctp_asconf.h> 47#include <netinet/sctp_sysctl.h> 48#include <netinet/sctp_indata.h> 49#include <sys/unistd.h> 50 |
51 | |
52/* Declare all of our malloc named types */ 53 54/* Note to Michael/Peter for mac-os, 55 * I think mac has this too since I 56 * do see the M_PCB type, so I 57 * will also put in the mac file the 58 * MALLOC_DECLARE. If this does not 59 * work for mac uncomment the defines for --- 20 unchanged lines hidden (view full) --- 80MALLOC_DEFINE(SCTP_M_ITER, "sctp_iter", "sctp iterator control"); 81MALLOC_DEFINE(SCTP_M_SOCKOPT, "sctp_socko", "sctp socket option"); 82 83 84#if defined(SCTP_USE_THREAD_BASED_ITERATOR) 85void 86sctp_wakeup_iterator(void) 87{ | 51/* Declare all of our malloc named types */ 52 53/* Note to Michael/Peter for mac-os, 54 * I think mac has this too since I 55 * do see the M_PCB type, so I 56 * will also put in the mac file the 57 * MALLOC_DECLARE. If this does not 58 * work for mac uncomment the defines for --- 20 unchanged lines hidden (view full) --- 79MALLOC_DEFINE(SCTP_M_ITER, "sctp_iter", "sctp iterator control"); 80MALLOC_DEFINE(SCTP_M_SOCKOPT, "sctp_socko", "sctp socket option"); 81 82 83#if defined(SCTP_USE_THREAD_BASED_ITERATOR) 84void 85sctp_wakeup_iterator(void) 86{ |
88 wakeup(&sctppcbinfo.iterator_running); | 87 wakeup(&SCTP_BASE_INFO(iterator_running)); |
89} 90 91static void 92sctp_iterator_thread(void *v) 93{ 94 SCTP_IPI_ITERATOR_WQ_LOCK(); | 88} 89 90static void 91sctp_iterator_thread(void *v) 92{ 93 SCTP_IPI_ITERATOR_WQ_LOCK(); |
95 sctppcbinfo.iterator_running = 0; | 94 SCTP_BASE_INFO(iterator_running) = 0; |
96 while (1) { | 95 while (1) { |
97 msleep(&sctppcbinfo.iterator_running, 98 &sctppcbinfo.ipi_iterator_wq_mtx, | 96 msleep(&SCTP_BASE_INFO(iterator_running), 97 &SCTP_BASE_INFO(ipi_iterator_wq_mtx), |
99 0, "waiting_for_work", 0); 100 sctp_iterator_worker(); 101 } 102} 103 104void 105sctp_startup_iterator(void) 106{ 107 int ret; 108 109 ret = kproc_create(sctp_iterator_thread, 110 (void *)NULL, | 98 0, "waiting_for_work", 0); 99 sctp_iterator_worker(); 100 } 101} 102 103void 104sctp_startup_iterator(void) 105{ 106 int ret; 107 108 ret = kproc_create(sctp_iterator_thread, 109 (void *)NULL, |
111 &sctppcbinfo.thread_proc, | 110 &SCTP_BASE_INFO(thread_proc), |
112 RFPROC, 113 SCTP_KTHREAD_PAGES, 114 SCTP_KTRHEAD_NAME); 115} 116 117#endif 118 119#ifdef INET6 --- 47 unchanged lines hidden (view full) --- 167 case IFT_XETHER: 168 case IFT_ISDNBASIC: 169 case IFT_ISDNPRIMARY: 170 case IFT_PTPSERIAL: 171 case IFT_OTHER: 172 case IFT_PPP: 173 case IFT_LOOP: 174 case IFT_SLIP: | 111 RFPROC, 112 SCTP_KTHREAD_PAGES, 113 SCTP_KTRHEAD_NAME); 114} 115 116#endif 117 118#ifdef INET6 --- 47 unchanged lines hidden (view full) --- 166 case IFT_XETHER: 167 case IFT_ISDNBASIC: 168 case IFT_ISDNPRIMARY: 169 case IFT_PTPSERIAL: 170 case IFT_OTHER: 171 case IFT_PPP: 172 case IFT_LOOP: 173 case IFT_SLIP: |
174 case IFT_GIF: |
|
175 case IFT_IP: 176 case IFT_IPOVERCDLC: 177 case IFT_IPOVERCLAW: 178 case IFT_VIRTUALIPADDRESS: 179 result = 1; 180 break; 181 default: 182 result = 0; 183 } 184 185 return (result); 186} 187 | 175 case IFT_IP: 176 case IFT_IPOVERCDLC: 177 case IFT_IPOVERCLAW: 178 case IFT_VIRTUALIPADDRESS: 179 result = 1; 180 break; 181 default: 182 result = 0; 183 } 184 185 return (result); 186} 187 |
188 |
|
188static void 189sctp_init_ifns_for_vrf(int vrfid) 190{ 191 /* 192 * Here we must apply ANY locks needed by the IFN we access and also 193 * make sure we lock any IFA that exists as we float through the 194 * list of IFA's 195 */ 196 struct ifnet *ifn; 197 struct ifaddr *ifa; 198 struct in6_ifaddr *ifa6; 199 struct sctp_ifa *sctp_ifa; 200 uint32_t ifa_flags; 201 202 TAILQ_FOREACH(ifn, &ifnet, if_list) { 203 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) { 204 if (ifa->ifa_addr == NULL) { 205 continue; 206 } | 189static void 190sctp_init_ifns_for_vrf(int vrfid) 191{ 192 /* 193 * Here we must apply ANY locks needed by the IFN we access and also 194 * make sure we lock any IFA that exists as we float through the 195 * list of IFA's 196 */ 197 struct ifnet *ifn; 198 struct ifaddr *ifa; 199 struct in6_ifaddr *ifa6; 200 struct sctp_ifa *sctp_ifa; 201 uint32_t ifa_flags; 202 203 TAILQ_FOREACH(ifn, &ifnet, if_list) { 204 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) { 205 if (ifa->ifa_addr == NULL) { 206 continue; 207 } |
207 if ((ifa->ifa_addr->sa_family != AF_INET) && 208 (ifa->ifa_addr->sa_family != AF_INET6) 209 ) { | 208 if ((ifa->ifa_addr->sa_family != AF_INET) && (ifa->ifa_addr->sa_family != AF_INET6)) { |
210 /* non inet/inet6 skip */ 211 continue; 212 } 213 if (ifa->ifa_addr->sa_family == AF_INET6) { | 209 /* non inet/inet6 skip */ 210 continue; 211 } 212 if (ifa->ifa_addr->sa_family == AF_INET6) { |
214 ifa6 = (struct in6_ifaddr *)ifa; 215 ifa_flags = ifa6->ia6_flags; | |
216 if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) { 217 /* skip unspecifed addresses */ 218 continue; 219 } | 213 if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) { 214 /* skip unspecifed addresses */ 215 continue; 216 } |
220 } else if (ifa->ifa_addr->sa_family == AF_INET) { | 217 } else { |
221 if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) { 222 continue; 223 } 224 } 225 if (sctp_is_desired_interface_type(ifa) == 0) { 226 /* non desired type */ 227 continue; 228 } | 218 if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) { 219 continue; 220 } 221 } 222 if (sctp_is_desired_interface_type(ifa) == 0) { 223 /* non desired type */ 224 continue; 225 } |
229 if ((ifa->ifa_addr->sa_family == AF_INET6) || 230 (ifa->ifa_addr->sa_family == AF_INET)) { 231 if (ifa->ifa_addr->sa_family == AF_INET6) { 232 ifa6 = (struct in6_ifaddr *)ifa; 233 ifa_flags = ifa6->ia6_flags; 234 } else { 235 ifa_flags = 0; 236 } 237 sctp_ifa = sctp_add_addr_to_vrf(vrfid, 238 (void *)ifn, 239 ifn->if_index, 240 ifn->if_type, 241 ifn->if_xname, 242 (void *)ifa, 243 ifa->ifa_addr, 244 ifa_flags, 0 245 ); 246 if (sctp_ifa) { 247 sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; 248 } | 226 if (ifa->ifa_addr->sa_family == AF_INET6) { 227 ifa6 = (struct in6_ifaddr *)ifa; 228 ifa_flags = ifa6->ia6_flags; 229 } else { 230 ifa_flags = 0; |
249 } | 231 } |
232 sctp_ifa = sctp_add_addr_to_vrf(vrfid, 233 (void *)ifn, 234 ifn->if_index, 235 ifn->if_type, 236 ifn->if_xname, 237 (void *)ifa, 238 ifa->ifa_addr, 239 ifa_flags, 240 0); 241 if (sctp_ifa) { 242 sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; 243 } |
|
250 } 251 } 252} 253 254 255void 256sctp_init_vrf_list(int vrfid) 257{ --- 6 unchanged lines hidden (view full) --- 264 265 /* 266 * Now we need to build all the ifn's for this vrf and there 267 * addresses 268 */ 269 sctp_init_ifns_for_vrf(vrfid); 270} 271 | 244 } 245 } 246} 247 248 249void 250sctp_init_vrf_list(int vrfid) 251{ --- 6 unchanged lines hidden (view full) --- 258 259 /* 260 * Now we need to build all the ifn's for this vrf and there 261 * addresses 262 */ 263 sctp_init_ifns_for_vrf(vrfid); 264} 265 |
272static uint8_t first_time = 0; 273 274 | |
275void 276sctp_addr_change(struct ifaddr *ifa, int cmd) 277{ 278 struct sctp_ifa *ifap = NULL; 279 uint32_t ifa_flags = 0; | 266void 267sctp_addr_change(struct ifaddr *ifa, int cmd) 268{ 269 struct sctp_ifa *ifap = NULL; 270 uint32_t ifa_flags = 0; |
280 struct in6_ifaddr *ifa6; | |
281 282 /* 283 * BSD only has one VRF, if this changes we will need to hook in the 284 * right things here to get the id to pass to the address managment 285 * routine. 286 */ | 271 272 /* 273 * BSD only has one VRF, if this changes we will need to hook in the 274 * right things here to get the id to pass to the address managment 275 * routine. 276 */ |
287 if (first_time == 0) { | 277 if (SCTP_BASE_VAR(first_time) == 0) { |
288 /* Special test to see if my ::1 will showup with this */ | 278 /* Special test to see if my ::1 will showup with this */ |
289 first_time = 1; | 279 SCTP_BASE_VAR(first_time) = 1; |
290 sctp_init_ifns_for_vrf(SCTP_DEFAULT_VRFID); 291 } 292 if ((cmd != RTM_ADD) && (cmd != RTM_DELETE)) { 293 /* don't know what to do with this */ 294 return; 295 } 296 if (ifa->ifa_addr == NULL) { 297 return; 298 } | 280 sctp_init_ifns_for_vrf(SCTP_DEFAULT_VRFID); 281 } 282 if ((cmd != RTM_ADD) && (cmd != RTM_DELETE)) { 283 /* don't know what to do with this */ 284 return; 285 } 286 if (ifa->ifa_addr == NULL) { 287 return; 288 } |
299 if ((ifa->ifa_addr->sa_family != AF_INET) && 300 (ifa->ifa_addr->sa_family != AF_INET6) 301 ) { | 289 if ((ifa->ifa_addr->sa_family != AF_INET) && (ifa->ifa_addr->sa_family != AF_INET6)) { |
302 /* non inet/inet6 skip */ 303 return; 304 } 305 if (ifa->ifa_addr->sa_family == AF_INET6) { | 290 /* non inet/inet6 skip */ 291 return; 292 } 293 if (ifa->ifa_addr->sa_family == AF_INET6) { |
306 ifa6 = (struct in6_ifaddr *)ifa; 307 ifa_flags = ifa6->ia6_flags; | 294 ifa_flags = ((struct in6_ifaddr *)ifa)->ia6_flags; |
308 if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) { 309 /* skip unspecifed addresses */ 310 return; 311 } | 295 if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) { 296 /* skip unspecifed addresses */ 297 return; 298 } |
312 } else if (ifa->ifa_addr->sa_family == AF_INET) { | 299 } else { |
313 if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) { 314 return; 315 } 316 } | 300 if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) { 301 return; 302 } 303 } |
304 |
|
317 if (sctp_is_desired_interface_type(ifa) == 0) { 318 /* non desired type */ 319 return; 320 } 321 if (cmd == RTM_ADD) { 322 ifap = sctp_add_addr_to_vrf(SCTP_DEFAULT_VRFID, (void *)ifa->ifa_ifp, 323 ifa->ifa_ifp->if_index, ifa->ifa_ifp->if_type, 324 ifa->ifa_ifp->if_xname, 325 (void *)ifa, ifa->ifa_addr, ifa_flags, 1); | 305 if (sctp_is_desired_interface_type(ifa) == 0) { 306 /* non desired type */ 307 return; 308 } 309 if (cmd == RTM_ADD) { 310 ifap = sctp_add_addr_to_vrf(SCTP_DEFAULT_VRFID, (void *)ifa->ifa_ifp, 311 ifa->ifa_ifp->if_index, ifa->ifa_ifp->if_type, 312 ifa->ifa_ifp->if_xname, 313 (void *)ifa, ifa->ifa_addr, ifa_flags, 1); |
326 } else if (cmd == RTM_DELETE) { | 314 } else { |
327 328 sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID, ifa->ifa_addr, 329 ifa->ifa_ifp->if_index, 330 ifa->ifa_ifp->if_xname 331 ); 332 /* 333 * We don't bump refcount here so when it completes the 334 * final delete will happen. 335 */ 336 } 337} 338 | 315 316 sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID, ifa->ifa_addr, 317 ifa->ifa_ifp->if_index, 318 ifa->ifa_ifp->if_xname 319 ); 320 /* 321 * We don't bump refcount here so when it completes the 322 * final delete will happen. 323 */ 324 } 325} 326 |
327void 328 sctp_add_or_del_interfaces(int (*pred) (struct ifnet *), int add){ 329 struct ifnet *ifn; 330 struct ifaddr *ifa; 331 332 TAILQ_FOREACH(ifn, &ifnet, if_list) { 333 if (!(*pred) (ifn)) { 334 continue; 335 } 336 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) { 337 sctp_addr_change(ifa, add ? RTM_ADD : RTM_DELETE); 338 } 339 } 340} 341 |
|
339struct mbuf * 340sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, 341 int how, int allonebuf, int type) 342{ 343 struct mbuf *m = NULL; 344 345 m = m_getm2(NULL, space_needed, how, type, want_header ? M_PKTHDR : 0); 346 if (m == NULL) { --- 16 unchanged lines hidden (view full) --- 363 return (NULL); 364 } 365 } 366 if (SCTP_BUF_NEXT(m)) { 367 sctp_m_freem(SCTP_BUF_NEXT(m)); 368 SCTP_BUF_NEXT(m) = NULL; 369 } 370#ifdef SCTP_MBUF_LOGGING | 342struct mbuf * 343sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, 344 int how, int allonebuf, int type) 345{ 346 struct mbuf *m = NULL; 347 348 m = m_getm2(NULL, space_needed, how, type, want_header ? M_PKTHDR : 0); 349 if (m == NULL) { --- 16 unchanged lines hidden (view full) --- 366 return (NULL); 367 } 368 } 369 if (SCTP_BUF_NEXT(m)) { 370 sctp_m_freem(SCTP_BUF_NEXT(m)); 371 SCTP_BUF_NEXT(m) = NULL; 372 } 373#ifdef SCTP_MBUF_LOGGING |
371 if (sctp_logging_level & SCTP_MBUF_LOGGING_ENABLE) { | 374 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { |
372 if (SCTP_BUF_IS_EXTENDED(m)) { 373 sctp_log_mb(m, SCTP_MBUF_IALLOC); 374 } 375 } 376#endif 377 return (m); 378} 379 380 381#ifdef SCTP_PACKET_LOGGING | 375 if (SCTP_BUF_IS_EXTENDED(m)) { 376 sctp_log_mb(m, SCTP_MBUF_IALLOC); 377 } 378 } 379#endif 380 return (m); 381} 382 383 384#ifdef SCTP_PACKET_LOGGING |
382 383int packet_log_writers = 0; 384int packet_log_end = 0; 385uint8_t packet_log_buffer[SCTP_PACKET_LOG_SIZE]; 386 387 | |
388void 389sctp_packet_log(struct mbuf *m, int length) 390{ 391 int *lenat, thisone; 392 void *copyto; 393 uint32_t *tick_tock; 394 int total_len; 395 int grabbed_lock = 0; --- 5 unchanged lines hidden (view full) --- 401 * where this started (thisbegin) x <--end points here 402 */ 403 total_len = SCTP_SIZE32((length + (4 * sizeof(int)))); 404 /* Log a packet to the buffer. */ 405 if (total_len > SCTP_PACKET_LOG_SIZE) { 406 /* Can't log this packet I have not a buffer big enough */ 407 return; 408 } | 385void 386sctp_packet_log(struct mbuf *m, int length) 387{ 388 int *lenat, thisone; 389 void *copyto; 390 uint32_t *tick_tock; 391 int total_len; 392 int grabbed_lock = 0; --- 5 unchanged lines hidden (view full) --- 398 * where this started (thisbegin) x <--end points here 399 */ 400 total_len = SCTP_SIZE32((length + (4 * sizeof(int)))); 401 /* Log a packet to the buffer. */ 402 if (total_len > SCTP_PACKET_LOG_SIZE) { 403 /* Can't log this packet I have not a buffer big enough */ 404 return; 405 } |
409 if (length < (SCTP_MIN_V4_OVERHEAD + sizeof(struct sctp_cookie_ack_chunk))) { | 406 if (length < (int)(SCTP_MIN_V4_OVERHEAD + sizeof(struct sctp_cookie_ack_chunk))) { |
410 return; 411 } | 407 return; 408 } |
412 atomic_add_int(&packet_log_writers, 1); | 409 atomic_add_int(&SCTP_BASE_VAR(packet_log_writers), 1); |
413try_again: | 410try_again: |
414 if (packet_log_writers > SCTP_PKTLOG_WRITERS_NEED_LOCK) { | 411 if (SCTP_BASE_VAR(packet_log_writers) > SCTP_PKTLOG_WRITERS_NEED_LOCK) { |
415 SCTP_IP_PKTLOG_LOCK(); 416 grabbed_lock = 1; 417again_locked: | 412 SCTP_IP_PKTLOG_LOCK(); 413 grabbed_lock = 1; 414again_locked: |
418 value = packet_log_end; 419 newval = packet_log_end + total_len; | 415 value = SCTP_BASE_VAR(packet_log_end); 416 newval = SCTP_BASE_VAR(packet_log_end) + total_len; |
420 if (newval >= SCTP_PACKET_LOG_SIZE) { 421 /* we wrapped */ 422 thisbegin = 0; 423 thisend = total_len; 424 } else { | 417 if (newval >= SCTP_PACKET_LOG_SIZE) { 418 /* we wrapped */ 419 thisbegin = 0; 420 thisend = total_len; 421 } else { |
425 thisbegin = packet_log_end; | 422 thisbegin = SCTP_BASE_VAR(packet_log_end); |
426 thisend = newval; 427 } | 423 thisend = newval; 424 } |
428 if (!(atomic_cmpset_int(&packet_log_end, value, thisend))) { | 425 if (!(atomic_cmpset_int(&SCTP_BASE_VAR(packet_log_end), value, thisend))) { |
429 goto again_locked; 430 } 431 } else { | 426 goto again_locked; 427 } 428 } else { |
432 value = packet_log_end; 433 newval = packet_log_end + total_len; | 429 value = SCTP_BASE_VAR(packet_log_end); 430 newval = SCTP_BASE_VAR(packet_log_end) + total_len; |
434 if (newval >= SCTP_PACKET_LOG_SIZE) { 435 /* we wrapped */ 436 thisbegin = 0; 437 thisend = total_len; 438 } else { | 431 if (newval >= SCTP_PACKET_LOG_SIZE) { 432 /* we wrapped */ 433 thisbegin = 0; 434 thisend = total_len; 435 } else { |
439 thisbegin = packet_log_end; | 436 thisbegin = SCTP_BASE_VAR(packet_log_end); |
440 thisend = newval; 441 } | 437 thisend = newval; 438 } |
442 if (!(atomic_cmpset_int(&packet_log_end, value, thisend))) { | 439 if (!(atomic_cmpset_int(&SCTP_BASE_VAR(packet_log_end), value, thisend))) { |
443 goto try_again; 444 } 445 } 446 /* Sanity check */ 447 if (thisend >= SCTP_PACKET_LOG_SIZE) { 448 printf("Insanity stops a log thisbegin:%d thisend:%d writers:%d lock:%d end:%d\n", 449 thisbegin, 450 thisend, | 440 goto try_again; 441 } 442 } 443 /* Sanity check */ 444 if (thisend >= SCTP_PACKET_LOG_SIZE) { 445 printf("Insanity stops a log thisbegin:%d thisend:%d writers:%d lock:%d end:%d\n", 446 thisbegin, 447 thisend, |
451 packet_log_writers, | 448 SCTP_BASE_VAR(packet_log_writers), |
452 grabbed_lock, | 449 grabbed_lock, |
453 packet_log_end); 454 packet_log_end = 0; | 450 SCTP_BASE_VAR(packet_log_end)); 451 SCTP_BASE_VAR(packet_log_end) = 0; |
455 goto no_log; 456 457 } | 452 goto no_log; 453 454 } |
458 lenat = (int *)&packet_log_buffer[thisbegin]; | 455 lenat = (int *)&SCTP_BASE_VAR(packet_log_buffer)[thisbegin]; |
459 *lenat = total_len; 460 lenat++; 461 *lenat = value; 462 lenat++; 463 tick_tock = (uint32_t *) lenat; 464 lenat++; 465 *tick_tock = sctp_get_tick_count(); 466 copyto = (void *)lenat; 467 thisone = thisend - sizeof(int); | 456 *lenat = total_len; 457 lenat++; 458 *lenat = value; 459 lenat++; 460 tick_tock = (uint32_t *) lenat; 461 lenat++; 462 *tick_tock = sctp_get_tick_count(); 463 copyto = (void *)lenat; 464 thisone = thisend - sizeof(int); |
468 lenat = (int *)&packet_log_buffer[thisone]; | 465 lenat = (int *)&SCTP_BASE_VAR(packet_log_buffer)[thisone]; |
469 *lenat = thisbegin; 470 if (grabbed_lock) { 471 SCTP_IP_PKTLOG_UNLOCK(); 472 grabbed_lock = 0; 473 } 474 m_copydata(m, 0, length, (caddr_t)copyto); 475no_log: 476 if (grabbed_lock) { 477 SCTP_IP_PKTLOG_UNLOCK(); 478 } | 466 *lenat = thisbegin; 467 if (grabbed_lock) { 468 SCTP_IP_PKTLOG_UNLOCK(); 469 grabbed_lock = 0; 470 } 471 m_copydata(m, 0, length, (caddr_t)copyto); 472no_log: 473 if (grabbed_lock) { 474 SCTP_IP_PKTLOG_UNLOCK(); 475 } |
479 atomic_subtract_int(&packet_log_writers, 1); | 476 atomic_subtract_int(&SCTP_BASE_VAR(packet_log_writers), 1); |
480} 481 482 483int 484sctp_copy_out_packet_log(uint8_t * target, int length) 485{ 486 /* 487 * We wind through the packet log starting at start copying up to 488 * length bytes out. We return the number of bytes copied. 489 */ 490 int tocopy, this_copy; 491 int *lenat; 492 int did_delay = 0; 493 494 tocopy = length; | 477} 478 479 480int 481sctp_copy_out_packet_log(uint8_t * target, int length) 482{ 483 /* 484 * We wind through the packet log starting at start copying up to 485 * length bytes out. We return the number of bytes copied. 486 */ 487 int tocopy, this_copy; 488 int *lenat; 489 int did_delay = 0; 490 491 tocopy = length; |
495 if (length < (2 * sizeof(int))) { | 492 if (length < (int)(2 * sizeof(int))) { |
496 /* not enough room */ 497 return (0); 498 } 499 if (SCTP_PKTLOG_WRITERS_NEED_LOCK) { | 493 /* not enough room */ 494 return (0); 495 } 496 if (SCTP_PKTLOG_WRITERS_NEED_LOCK) { |
500 atomic_add_int(&packet_log_writers, SCTP_PKTLOG_WRITERS_NEED_LOCK); | 497 atomic_add_int(&SCTP_BASE_VAR(packet_log_writers), SCTP_PKTLOG_WRITERS_NEED_LOCK); |
501again: | 498again: |
502 if ((did_delay == 0) && (packet_log_writers != SCTP_PKTLOG_WRITERS_NEED_LOCK)) { | 499 if ((did_delay == 0) && (SCTP_BASE_VAR(packet_log_writers) != SCTP_PKTLOG_WRITERS_NEED_LOCK)) { |
503 /* 504 * we delay here for just a moment hoping the 505 * writer(s) that were present when we entered will 506 * have left and we only have locking ones that will 507 * contend with us for the lock. This does not 508 * assure 100% access, but its good enough for a 509 * logging facility like this. 510 */ 511 did_delay = 1; 512 DELAY(10); 513 goto again; 514 } 515 } 516 SCTP_IP_PKTLOG_LOCK(); 517 lenat = (int *)target; | 500 /* 501 * we delay here for just a moment hoping the 502 * writer(s) that were present when we entered will 503 * have left and we only have locking ones that will 504 * contend with us for the lock. This does not 505 * assure 100% access, but its good enough for a 506 * logging facility like this. 507 */ 508 did_delay = 1; 509 DELAY(10); 510 goto again; 511 } 512 } 513 SCTP_IP_PKTLOG_LOCK(); 514 lenat = (int *)target; |
518 *lenat = packet_log_end; | 515 *lenat = SCTP_BASE_VAR(packet_log_end); |
519 lenat++; 520 this_copy = min((length - sizeof(int)), SCTP_PACKET_LOG_SIZE); | 516 lenat++; 517 this_copy = min((length - sizeof(int)), SCTP_PACKET_LOG_SIZE); |
521 memcpy((void *)lenat, (void *)packet_log_buffer, this_copy); | 518 memcpy((void *)lenat, (void *)SCTP_BASE_VAR(packet_log_buffer), this_copy); |
522 if (SCTP_PKTLOG_WRITERS_NEED_LOCK) { | 519 if (SCTP_PKTLOG_WRITERS_NEED_LOCK) { |
523 atomic_subtract_int(&packet_log_writers, | 520 atomic_subtract_int(&SCTP_BASE_VAR(packet_log_writers), |
524 SCTP_PKTLOG_WRITERS_NEED_LOCK); 525 } 526 SCTP_IP_PKTLOG_UNLOCK(); 527 return (this_copy + sizeof(int)); 528} 529 530#endif | 521 SCTP_PKTLOG_WRITERS_NEED_LOCK); 522 } 523 SCTP_IP_PKTLOG_UNLOCK(); 524 return (this_copy + sizeof(int)); 525} 526 527#endif |