ip_id.c (302054) | ip_id.c (302372) |
---|---|
1 2/*- 3 * Copyright (c) 2008 Michael J. Silbersack. 4 * 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 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1 2/*- 3 * Copyright (c) 2008 Michael J. Silbersack. 4 * 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 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/sys/netinet/ip_id.c 302054 2016-06-21 13:48:49Z bz $"); | 29__FBSDID("$FreeBSD: head/sys/netinet/ip_id.c 302372 2016-07-06 14:09:49Z nwhitehorn $"); |
30 31/* 32 * IP ID generation is a fascinating topic. 33 * 34 * In order to avoid ID collisions during packet reassembly, common sense 35 * dictates that the period between reuse of IDs be as large as possible. 36 * This leads to the classic implementation of a system-wide counter, thereby 37 * ensuring that IDs repeat only once every 2^16 packets. --- 232 unchanged lines hidden (view full) --- 270 */ 271 ip->ip_id = htons((*(uint64_t *)zpcpu_get(V_ip_id)) & 0xffff); 272 } 273} 274 275static void 276ipid_sysinit(void) 277{ | 30 31/* 32 * IP ID generation is a fascinating topic. 33 * 34 * In order to avoid ID collisions during packet reassembly, common sense 35 * dictates that the period between reuse of IDs be as large as possible. 36 * This leads to the classic implementation of a system-wide counter, thereby 37 * ensuring that IDs repeat only once every 2^16 packets. --- 232 unchanged lines hidden (view full) --- 270 */ 271 ip->ip_id = htons((*(uint64_t *)zpcpu_get(V_ip_id)) & 0xffff); 272 } 273} 274 275static void 276ipid_sysinit(void) 277{ |
278 int i; |
|
278 279 mtx_init(&V_ip_id_mtx, "ip_id_mtx", NULL, MTX_DEF); 280 V_ip_id = counter_u64_alloc(M_WAITOK); | 279 280 mtx_init(&V_ip_id_mtx, "ip_id_mtx", NULL, MTX_DEF); 281 V_ip_id = counter_u64_alloc(M_WAITOK); |
281 for (int i = 0; i < mp_ncpus; i++) | 282 283 CPU_FOREACH(i) |
282 arc4rand(zpcpu_get_cpu(V_ip_id, i), sizeof(uint64_t), 0); 283} 284VNET_SYSINIT(ip_id, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, ipid_sysinit, NULL); 285 286static void 287ipid_sysuninit(void) 288{ 289 290 if (V_id_array != NULL) { 291 free(V_id_array, M_IPID); 292 free(V_id_bits, M_IPID); 293 } 294 counter_u64_free(V_ip_id); 295 mtx_destroy(&V_ip_id_mtx); 296} 297VNET_SYSUNINIT(ip_id, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, ipid_sysuninit, NULL); | 284 arc4rand(zpcpu_get_cpu(V_ip_id, i), sizeof(uint64_t), 0); 285} 286VNET_SYSINIT(ip_id, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, ipid_sysinit, NULL); 287 288static void 289ipid_sysuninit(void) 290{ 291 292 if (V_id_array != NULL) { 293 free(V_id_array, M_IPID); 294 free(V_id_bits, M_IPID); 295 } 296 counter_u64_free(V_ip_id); 297 mtx_destroy(&V_ip_id_mtx); 298} 299VNET_SYSUNINIT(ip_id, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, ipid_sysuninit, NULL); |