Example #1
0
static inline struct tc_class *tc_class_add(struct tc_device *n, char *id, char qdisc, char *parentid, char *leafid)
{
    struct tc_class *c = tc_class_index_find(n, id, 0);

    if(!c) {
        debug(D_TC_LOOP, "TC: Creating in device '%s', class id '%s', parentid '%s', leafid '%s'", n->id, id, parentid?parentid:"", leafid?leafid:"");

        c = callocz(1, sizeof(struct tc_class));

        if(n->classes) n->classes->prev = c;
        c->next = n->classes;
        n->classes = c;

        c->id = strdupz(id);
        c->hash = simple_hash(c->id);

        c->isqdisc = qdisc;
        if(parentid && *parentid) {
            c->parentid = strdupz(parentid);
            c->parent_hash = simple_hash(c->parentid);
        }

        if(leafid && *leafid) {
            c->leafid = strdupz(leafid);
            c->leaf_hash = simple_hash(c->leafid);
        }

        if(unlikely(tc_class_index_add(n, c) != c))
            error("plugin_tc: INTERNAL ERROR: attempt index class '%s' on device '%s': already exists", c->id, n->id);
    }
    return(c);
}
Example #2
0
static inline struct tc_class *tc_class_add(struct tc_device *n, char *id, char *parentid, char *leafid)
{
	struct tc_class *c = tc_class_index_find(n, id, 0);

	if(!c) {
		debug(D_TC_LOOP, "TC: Creating in device '%s', class id '%s', parentid '%s', leafid '%s'", n->id, id, parentid?parentid:"", leafid?leafid:"");

		c = calloc(1, sizeof(struct tc_class));
		if(!c) {
			fatal("Cannot allocate memory for tc class");
			return NULL;
		}

		if(n->classes) n->classes->prev = c;
		c->next = n->classes;
		n->classes = c;

		c->id = strdup(id);
		if(!c->id) {
			free(c);
			return NULL;
		}
		c->hash = simple_hash(c->id);

		if(parentid && *parentid) {
			c->parentid = strdup(parentid);
			c->parent_hash = simple_hash(c->parentid);
		}

		if(leafid && *leafid) {
			c->leafid = strdup(leafid);
			c->leaf_hash = simple_hash(c->leafid);
		}

		tc_class_index_add(n, c);
	}

	c->seen = 1;

	return(c);
}