uipc_mbuf.c (117770) | uipc_mbuf.c (119644) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 20 unchanged lines hidden (view full) --- 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94 34 */ 35 36#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1982, 1986, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 20 unchanged lines hidden (view full) --- 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94 34 */ 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/sys/kern/uipc_mbuf.c 117770 2003-07-19 06:03:48Z silby $"); | 37__FBSDID("$FreeBSD: head/sys/kern/uipc_mbuf.c 119644 2003-09-01 05:55:37Z silby $"); |
38 39#include "opt_mac.h" 40#include "opt_param.h" 41#include "opt_mbuf_stress_test.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/kernel.h> --- 832 unchanged lines hidden (view full) --- 878 m_defragfailure++; 879#endif 880 if (m_new) 881 m_free(m_new); 882 if (m_final) 883 m_freem(m_final); 884 return (NULL); 885} | 38 39#include "opt_mac.h" 40#include "opt_param.h" 41#include "opt_mbuf_stress_test.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/kernel.h> --- 832 unchanged lines hidden (view full) --- 878 m_defragfailure++; 879#endif 880 if (m_new) 881 m_free(m_new); 882 if (m_final) 883 m_freem(m_final); 884 return (NULL); 885} |
886 887#ifdef MBUF_STRESS_TEST 888 889/* 890 * Fragment an mbuf chain. There's no reason you'd ever want to do 891 * this in normal usage, but it's great for stress testing various 892 * mbuf consumers. 893 * 894 * If fragmentation is not possible, the original chain will be 895 * returned. 896 * 897 * Possible length values: 898 * 0 no fragmentation will occur 899 * > 0 each fragment will be of the specified length 900 * -1 each fragment will be the same random value in length 901 * -2 each fragment's length will be entirely random 902 * (Random values range from 1 to 256) 903 */ 904struct mbuf * 905m_fragment(struct mbuf *m0, int how, int length) 906{ 907 struct mbuf *m_new = NULL, *m_final = NULL; 908 int progress = 0; 909 910 if (!(m0->m_flags & M_PKTHDR)) 911 return (m0); 912 913 if ((length == 0) || (length < -2)) 914 return (m0); 915 916 m_fixhdr(m0); /* Needed sanity check */ 917 918 m_final = m_getcl(how, MT_DATA, M_PKTHDR); 919 920 if (m_final == NULL) 921 goto nospace; 922 923 if (m_dup_pkthdr(m_final, m0, how) == NULL) 924 goto nospace; 925 926 m_new = m_final; 927 928 if (length == -1) 929 length = 1 + (arc4random() & 255); 930 931 while (progress < m0->m_pkthdr.len) { 932 int fraglen; 933 934 if (length > 0) 935 fraglen = length; 936 else 937 fraglen = 1 + (arc4random() & 255); 938 if (fraglen > m0->m_pkthdr.len - progress) 939 fraglen = m0->m_pkthdr.len - progress; 940 941 if (fraglen > MCLBYTES) 942 fraglen = MCLBYTES; 943 944 if (m_new == NULL) { 945 m_new = m_getcl(how, MT_DATA, 0); 946 if (m_new == NULL) 947 goto nospace; 948 } 949 950 m_copydata(m0, progress, fraglen, mtod(m_new, caddr_t)); 951 progress += fraglen; 952 m_new->m_len = fraglen; 953 if (m_new != m_final) 954 m_cat(m_final, m_new); 955 m_new = NULL; 956 } 957 m_freem(m0); 958 m0 = m_final; 959 return (m0); 960nospace: 961 if (m_new) 962 m_free(m_new); 963 if (m_final) 964 m_freem(m_final); 965 /* Return the original chain on failure */ 966 return (m0); 967} 968 969#endif |
|