Fixes krefs in iproute
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Jan 2014 16:57:07 +0000 (08:57 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Jan 2014 16:57:07 +0000 (08:57 -0800)
It compiles, but still missing some printf symbols.

kern/include/ip.h
kern/src/net/iproute.c

index 5b92e2e..499a97b 100644 (file)
@@ -442,7 +442,7 @@ struct      RouteTree
        uint8_t ifcid;          /* must match ifc->id */
        struct Ipifc    *ifc;
        char    tag[4];
-       int     ref;
+       struct kref     kref;
 };
 
 struct V4route
index 82c0e55..144450a 100644 (file)
@@ -64,7 +64,7 @@ allocroute(int type)
        memset(r, 0, n);
        r->rt.type = type;
        r->rt.ifc = NULL;
-       kref_init(&r->rt.ref, fake_release, 1);
+       kref_init(&r->rt.kref, fake_release, 1);
 
        return r;
 }
@@ -280,7 +280,7 @@ addnode(struct Fs *f, struct route **cur, struct route *new)
                        p->rt.ifcid = -1;
                        copygate(p, new);
                } else if(new->rt.type & Rifc)
-                       p->rt.ref++;
+                       kref_get(&p->rt.kref, 1);
                freeroute(new);
                break;
        case Rcontained:
@@ -424,7 +424,8 @@ v4delroute(struct Fs *f, uint8_t *a, uint8_t *mask, int dolock)
                r = looknode(&f->v4root[h], &rt);
                if(r) {
                        p = *r;
-                       if(--(p->ref) == 0){
+                       /* TODO: use a release method. put returns TRUE for the last ref. */
+                       if (kref_put(&p->rt.kref)) {
                                *r = 0;
                                addqueue(&f->queue, p->rt.left);
                                addqueue(&f->queue, p->rt.mid);
@@ -468,7 +469,8 @@ v6delroute(struct Fs *f, uint8_t *a, uint8_t *mask, int dolock)
                r = looknode(&f->v6root[h], &rt);
                if(r) {
                        p = *r;
-                       if(--(p->ref) == 0){
+                       /* TODO: use a release method. put returns TRUE for the last ref. */
+                       if (kref_put(&p->rt.kref)) {
                                *r = 0;
                                addqueue(&f->queue, p->rt.left);
                                addqueue(&f->queue, p->rt.mid);