iproute.c compiles
authorRonald G. Minnich <rminnich@google.com>
Fri, 17 Jan 2014 17:36:01 +0000 (09:36 -0800)
committerRonald G. Minnich <rminnich@google.com>
Fri, 17 Jan 2014 17:39:05 +0000 (09:39 -0800)
Signed-off-by: Ronald G. Minnich <rminnich@google.com>
kern/include/stdio.h
kern/src/net/iproute.c
kern/src/printfmt.c

index e25ead5..67b6e93 100644 (file)
@@ -51,4 +51,5 @@ int   vfprintf(int fd, const char *NTS fmt, va_list);
 // lib/readline.c
 int readline(char *buf, size_t buf_l, const char *prompt, ...);
 
+char *seprintf(char *buf, char *end, const char *fmt, ...);
 #endif /* !ROS_INC_STDIO_H */
index 144450a..50a36f3 100644 (file)
@@ -23,8 +23,7 @@ struct route* v6freelist;
 rwlock_t       routelock;
 uint32_t       v4routegeneration, v6routegeneration;
 
-static void
-freeroute(struct route *r)
+static void freeroute(struct route *r)
 {
        struct route **l;
 
@@ -38,6 +37,15 @@ freeroute(struct route *r)
        *l = r;
 }
 
+static void
+freeroute_from_ref(struct kref *ref)
+{
+       struct RouteTree *rt = container_of(ref, struct RouteTree, kref);
+       struct route *r = container_of(rt, struct route, rt);
+       freeroute(r);
+}
+
+
 static struct route*
 allocroute(int type)
 {
@@ -64,7 +72,7 @@ allocroute(int type)
        memset(r, 0, n);
        r->rt.type = type;
        r->rt.ifc = NULL;
-       kref_init(&r->rt.kref, fake_release, 1);
+       kref_init(&r->rt.kref, freeroute_from_ref, 1);
 
        return r;
 }
@@ -424,17 +432,16 @@ v4delroute(struct Fs *f, uint8_t *a, uint8_t *mask, int dolock)
                r = looknode(&f->v4root[h], &rt);
                if(r) {
                        p = *r;
-                       /* TODO: use a release method. put returns TRUE for the last ref. */
-                       if (kref_put(&p->rt.kref)) {
+                       if(kref_refcnt(&p->rt.kref) == 1){
                                *r = 0;
                                addqueue(&f->queue, p->rt.left);
                                addqueue(&f->queue, p->rt.mid);
                                addqueue(&f->queue, p->rt.right);
-                               freeroute(p);
+                               kref_put(&p->rt.kref);
                                while((p = f->queue)) {
                                        f->queue = p->rt.mid;
                                        walkadd(f, &f->v4root[h], p->rt.left);
-                                       freeroute(p);
+                                       kref_put(&p->rt.kref);
                                }
                        }
                }
@@ -469,12 +476,12 @@ v6delroute(struct Fs *f, uint8_t *a, uint8_t *mask, int dolock)
                r = looknode(&f->v6root[h], &rt);
                if(r) {
                        p = *r;
-                       /* TODO: use a release method. put returns TRUE for the last ref. */
-                       if (kref_put(&p->rt.kref)) {
+                       if(kref_refcnt(&p->rt.kref) == 1){
                                *r = 0;
                                addqueue(&f->queue, p->rt.left);
                                addqueue(&f->queue, p->rt.mid);
                                addqueue(&f->queue, p->rt.right);
+
                                freeroute(p);
                                while((p = f->queue)) {
                                        f->queue = p->rt.mid;
index 56431f5..2050782 100644 (file)
@@ -292,3 +292,24 @@ int snprintf(char *buf, int n, const char *fmt, ...)
        check_poison("snprintf");
        return rc;
 }
+
+/* convenience function: do a print, return the pointer to the end. */
+char *seprintf(char *buf, char *end, const char *fmt, ...)
+{
+       va_list ap;
+       int rc;
+       int n = end - buf;
+
+       if (n <= 0)
+               return buf;
+
+       va_start(ap, fmt);
+       rc = vsnprintf(buf, n, fmt, ap);
+       va_end(ap);
+       check_poison("seprintf");
+
+       if (rc >= 0)
+               return buf + rc;
+       else
+               return buf;
+}