[netfilter-cvslog] r3582 - in trunk/nfsim: core kernelenv
rusty at netfilter.org
rusty at netfilter.org
Sun Jan 9 13:59:34 CET 2005
Author: rusty at netfilter.org
Date: 2005-01-09 13:59:33 +0100 (Sun, 09 Jan 2005)
New Revision: 3582
Modified:
trunk/nfsim/core/message.c
trunk/nfsim/core/talloc.c
trunk/nfsim/core/talloc.h
trunk/nfsim/kernelenv/kernelenv.c
Log:
New talloc version from samba4 source.
Don't ever make packet *less* writable than it was (causes ICMP error NAT to fail, unreasonably)
Modified: trunk/nfsim/core/message.c
===================================================================
--- trunk/nfsim/core/message.c 2005-01-07 19:15:24 UTC (rev 3581)
+++ trunk/nfsim/core/message.c 2005-01-09 12:59:33 UTC (rev 3582)
@@ -352,7 +352,7 @@
return n;
}
- msg = talloc_zero_named_const(NULL,
+ msg = _talloc_zero(NULL,
sizeof(struct nf_userspace_message) + n, "copy_to_user");
msg->type = UM_KERNELOP;
Modified: trunk/nfsim/core/talloc.c
===================================================================
--- trunk/nfsim/core/talloc.c 2005-01-07 19:15:24 UTC (rev 3581)
+++ trunk/nfsim/core/talloc.c 2005-01-09 12:59:33 UTC (rev 3582)
@@ -27,20 +27,22 @@
*/
-/*
- if you need to build this outside of the Samba source tree then please define _STANDALONE_
-*/
-#define _STANDALONE_
-#ifdef _STANDALONE_
+#ifdef _SAMBA_BUILD_
+#include "includes.h"
+#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include <stdint.h>
#include "talloc.h"
-#else
-#include "includes.h"
#endif
+/* use this to force every realloc to change the pointer, to stress test
+ code that might not cope */
+#define ALWAYS_REALLOC 0
+
+
#define MAX_TALLOC_SIZE 0x10000000
#define TALLOC_MAGIC 0xe814ec4f
#define TALLOC_MAGIC_FREE 0x7faebef3
@@ -53,14 +55,19 @@
#endif
#ifndef discard_const_p
-#define discard_const_p(type, ptr) ((type *)(ptr))
+#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
+# define discard_const_p(type, ptr) ((type *)((intptr_t)(ptr)))
+#else
+# define discard_const_p(type, ptr) ((type *)(ptr))
#endif
+#endif
/* this null_context is only used if talloc_enable_leak_report() or
talloc_enable_leak_report_full() is called, otherwise it remains
NULL
*/
static const void *null_context;
+static void *cleanup_context;
struct talloc_reference_handle {
@@ -223,9 +230,13 @@
*/
void *talloc_reference(const void *context, const void *ptr)
{
- struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
+ struct talloc_chunk *tc;
struct talloc_reference_handle *handle;
+ if (ptr == NULL) return NULL;
+
+ tc = talloc_chunk_from_ptr(ptr);
handle = talloc_named_const(context, sizeof(*handle), TALLOC_MAGIC_REFERENCE);
+
if (handle == NULL) return NULL;
/* note that we hang the destructor off the handle, not the
@@ -274,6 +285,10 @@
struct talloc_chunk *tc_p, *new_p;
void *new_parent;
+ if (ptr == NULL) {
+ return -1;
+ }
+
if (context == NULL) {
context = null_context;
}
@@ -531,7 +546,15 @@
/* by resetting magic we catch users of the old memory */
tc->magic = TALLOC_MAGIC_FREE;
+#if ALWAYS_REALLOC
+ new_ptr = malloc(size + sizeof(*tc));
+ if (new_ptr) {
+ memcpy(new_ptr, tc, tc->size + sizeof(*tc));
+ free(tc);
+ }
+#else
new_ptr = realloc(tc, size + sizeof(*tc));
+#endif
if (!new_ptr) {
tc->magic = TALLOC_MAGIC;
return NULL;
@@ -542,6 +565,9 @@
if (tc->parent) {
tc->parent->child = new_ptr;
}
+ if (tc->child) {
+ tc->child->parent = new_ptr;
+ }
if (tc->prev) {
tc->prev->next = tc;
@@ -702,9 +728,6 @@
}
if (ptr == NULL) return;
- if (!f)
- f = stdout;
-
fprintf(f,"full talloc report on '%s' (total %lu bytes in %lu blocks)\n",
talloc_get_name(ptr),
(unsigned long)talloc_total_size(ptr),
@@ -725,9 +748,6 @@
}
if (ptr == NULL) return;
- if (!f)
- f = stdout;
-
fprintf(f,"talloc report on '%s' (total %lu bytes in %lu blocks)\n",
talloc_get_name(ptr),
(unsigned long)talloc_total_size(ptr),
@@ -785,13 +805,12 @@
/*
talloc and zero memory.
*/
-void *talloc_zero_named_const(const void *ctx, size_t size, const char *name)
+void *_talloc_zero(const void *ctx, size_t size, const char *name)
{
- void *p = talloc_size(ctx, size);
+ void *p = talloc_named_const(ctx, size, name);
if (p) {
memset(p, '\0', size);
- talloc_set_name_const(p, name);
}
return p;
@@ -838,34 +857,27 @@
for (len=0; p[len] && len<n; len++) ;
- ret = talloc_size(t, len + 1);
+ ret = _talloc(t, len + 1);
if (!ret) { return NULL; }
memcpy(ret, p, len);
ret[len] = 0;
+ talloc_set_name_const(ret, ret);
return ret;
}
-#ifndef VA_COPY
-#ifdef HAVE_VA_COPY
-#define VA_COPY(dest, src) __va_copy(dest, src)
-#else
-#define VA_COPY(dest, src) (dest) = (src)
-#endif
-#endif
-
char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
{
int len;
char *ret;
va_list ap2;
- VA_COPY(ap2, ap);
+ va_copy(ap2, ap);
len = vsnprintf(NULL, 0, fmt, ap2);
- ret = talloc_size(t, len+1);
+ ret = _talloc(t, len+1);
if (ret) {
- VA_COPY(ap2, ap);
+ va_copy(ap2, ap);
vsnprintf(ret, len+1, fmt, ap2);
talloc_set_name_const(ret, ret);
}
@@ -903,7 +915,7 @@
int len, s_len;
va_list ap2;
- VA_COPY(ap2, ap);
+ va_copy(ap2, ap);
if (s) {
s_len = strlen(s);
@@ -912,10 +924,10 @@
}
len = vsnprintf(NULL, 0, fmt, ap2);
- s = talloc_realloc(NULL, s, char, s_len + len+1);
+ s = talloc_realloc(NULL, s, s_len + len+1);
if (!s) return NULL;
- VA_COPY(ap2, ap);
+ va_copy(ap2, ap);
vsnprintf(s+s_len, len+1, fmt, ap2);
talloc_set_name_const(s, s);
@@ -952,12 +964,12 @@
/*
alloc an zero array, checking for integer overflow in the array size
*/
-void *talloc_zero_array_size(const void *ctx, size_t el_size, unsigned count, const char *name)
+void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name)
{
if (count >= MAX_TALLOC_SIZE/el_size) {
return NULL;
}
- return talloc_zero_named_const(ctx, el_size * count, name);
+ return _talloc_zero(ctx, el_size * count, name);
}
@@ -969,7 +981,11 @@
if (count >= MAX_TALLOC_SIZE/el_size) {
return NULL;
}
- return _talloc_realloc(ctx, ptr, el_size * count, name);
+ ptr = talloc_realloc(ctx, ptr, el_size * count);
+ if (ptr) {
+ talloc_set_name_const(ptr, name);
+ }
+ return ptr;
}
/*
@@ -981,3 +997,23 @@
{
return _talloc_realloc(context, ptr, size, NULL);
}
+
+
+static void talloc_autofree(void)
+{
+ talloc_free(cleanup_context);
+ cleanup_context = NULL;
+}
+
+/*
+ return a context which will be auto-freed on exit
+ this is useful for reducing the noise in leak reports
+*/
+void *talloc_autofree_context(void)
+{
+ if (cleanup_context == NULL) {
+ cleanup_context = talloc_named_const(NULL, 0, "autofree_context");
+ atexit(talloc_autofree);
+ }
+ return cleanup_context;
+}
Modified: trunk/nfsim/core/talloc.h
===================================================================
--- trunk/nfsim/core/talloc.h 2005-01-07 19:15:24 UTC (rev 3581)
+++ trunk/nfsim/core/talloc.h 2005-01-09 12:59:33 UTC (rev 3582)
@@ -20,7 +20,12 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+
+/* this is only needed for compatibility with the old talloc */
+typedef void TALLOC_CTX;
+#ifndef _SAMBA_BUILD_
#include <stdarg.h>
+#endif
/*
this uses a little trick to allow __LINE__ to be stringified
@@ -32,20 +37,26 @@
/* useful macros for creating type checked pointers */
#define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
-#define talloc_zero(ctx, type) (type *)talloc_zero_named_const(ctx, sizeof(type), #type)
+#define talloc_p(ctx, type) talloc(ctx, type)
+#define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__)
+#define talloc_zero(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), __location__)
+#define talloc_realloc(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
+#define talloc_new(ctx) talloc_named_const(ctx, 0, "talloc_new: " __location__)
+#define talloc_zero_p(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
+#define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, __location__)
#define talloc_array(ctx, type, count) (type *)talloc_array_size(ctx, sizeof(type), count, __location__)
-#define talloc_zero_array(ctx, type, count) (type *)talloc_zero_array_size(ctx, sizeof(type), count, __location__)
-#define talloc_realloc(ctx, p, type, count) (type *)talloc_realloc_array(ctx, p, sizeof(type), count, __location__)
-#define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__)
-#define talloc_realloc_size(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
+#define talloc_realloc_p(ctx, p, type, count) (type *)talloc_realloc_array(ctx, p, sizeof(type), count, __location__)
#define talloc_memdup(t, p, size) _talloc_memdup(t, p, size, __location__)
#define talloc_destroy(ctx) talloc_free(ctx)
-#ifdef __GNUC__
-#define PRINTF_ATTRIBUTE(a1,a2) __attribute__((format(printf,a1,a2)))
-#endif
+#define malloc_p(type) (type *)malloc(sizeof(type))
+#define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count)
+#define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count)
+#define data_blob(ptr, size) data_blob_named(ptr, size, "DATA_BLOB: "__location__)
+#define data_blob_talloc(ctx, ptr, size) data_blob_talloc_named(ctx, ptr, size, "DATA_BLOB: "__location__)
+
#ifndef PRINTF_ATTRIBUTE
#define PRINTF_ATTRIBUTE(a1, a2)
#endif
@@ -73,7 +84,7 @@
void talloc_report(const void *ptr, FILE *f);
void talloc_enable_leak_report(void);
void talloc_enable_leak_report_full(void);
-void *talloc_zero_named_const(const void *ctx, size_t size, const char *name);
+void *_talloc_zero(const void *ctx, size_t size, const char *name);
void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name);
char *talloc_strdup(const void *t, const char *p);
char *talloc_strndup(const void *t, const char *p, size_t n);
@@ -82,8 +93,10 @@
char *talloc_asprintf_append(char *s,
const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
void *talloc_array_size(const void *ctx, size_t el_size, unsigned count, const char *name);
-void *talloc_zero_array_size(const void *ctx, size_t el_size, unsigned count, const char *name);
+void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name);
void *talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name);
void *talloc_realloc_fn(const void *context, void *ptr, size_t size);
+void *talloc_autofree_context(void);
+
#endif
Modified: trunk/nfsim/kernelenv/kernelenv.c
===================================================================
--- trunk/nfsim/kernelenv/kernelenv.c 2005-01-07 19:15:24 UTC (rev 3581)
+++ trunk/nfsim/kernelenv/kernelenv.c 2005-01-09 12:59:33 UTC (rev 3582)
@@ -437,6 +437,10 @@
/* Use skb_copy_bits, which handles packet whatever shape. */
skb_copy_bits(*pskb, 0, data, (*pskb)->len);
+ extra = field_value(*pskb, "extra_data");
+ if (extra && writable_len < extra->writable_len)
+ writable_len = extra->writable_len;
+
/* Always reallocate, to catch cached pointers. */
new = nfsim_nonlinear_skb(data, writable_len,
data + writable_len,
@@ -881,7 +885,7 @@
if (should_i_fail(__func__))
return NULL;
- return talloc_zero_named_const(ctx, size, location);
+ return _talloc_zero(ctx, size, location);
}
kmem_cache_t *kmem_cache_create(const char *name, size_t objsize,
More information about the netfilter-cvslog
mailing list