diff options
-rw-r--r-- | interface-ip.c | 8 | ||||
-rw-r--r-- | interface.c | 5 | ||||
-rw-r--r-- | proto.c | 4 | ||||
-rw-r--r-- | utils.c | 7 | ||||
-rw-r--r-- | utils.h | 8 |
5 files changed, 11 insertions, 21 deletions
diff --git a/interface-ip.c b/interface-ip.c index 7f10120..612fd5f 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -95,7 +95,7 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6) if ((cur = tb[ROUTE_MTU]) != NULL) route->mtu = blobmsg_get_u32(cur); - vlist_add(&ip->route, &route->node); + vlist_add(&ip->route, &route->node, &route->mask); return; error: @@ -420,8 +420,6 @@ interface_ip_init(struct interface_ip_settings *ip, struct interface *iface) ip->enabled = true; vlist_simple_init(&ip->dns_search, struct dns_search_domain, node); vlist_simple_init(&ip->dns_servers, struct dns_server, node); - vlist_init(&ip->route, route_cmp, interface_update_proto_route, - struct device_route, node, mask); - vlist_init(&ip->addr, addr_cmp, interface_update_proto_addr, - struct device_addr, node, mask); + vlist_init(&ip->route, route_cmp, interface_update_proto_route); + vlist_init(&ip->addr, addr_cmp, interface_update_proto_addr); } diff --git a/interface.c b/interface.c index 6e3feeb..4d9aa8a 100644 --- a/interface.c +++ b/interface.c @@ -349,7 +349,7 @@ interface_add(struct interface *iface, struct blob_attr *config) iface->ifname = blobmsg_data(cur); iface->config = config; - vlist_add(&interfaces, &iface->node); + vlist_add(&interfaces, &iface->node, iface->name); } int @@ -553,8 +553,7 @@ interface_update(struct vlist_tree *tree, struct vlist_node *node_new, static void __init interface_init_list(void) { - vlist_init(&interfaces, avl_strcmp, interface_update, - struct interface, node, name); + vlist_init(&interfaces, avl_strcmp, interface_update); interfaces.keep_old = true; interfaces.no_delete = true; } @@ -142,7 +142,7 @@ parse_addr(struct interface *iface, const char *str, bool v6, int mask, if (ext) addr->flags |= DEVADDR_EXTERNAL; - vlist_add(&iface->proto_ip.addr, &addr->node); + vlist_add(&iface->proto_ip.addr, &addr->node, &addr->mask); return true; } @@ -184,7 +184,7 @@ parse_gateway_option(struct interface *iface, struct blob_attr *attr, bool v6) route->mask = 0; route->flags = DEVADDR_DEVICE | (v6 ? DEVADDR_INET6 : DEVADDR_INET4); - vlist_add(&iface->proto_ip.route, &route->node); + vlist_add(&iface->proto_ip.route, &route->node, &route->mask); return true; } @@ -9,10 +9,8 @@ avl_strcmp(const void *k1, const void *k2, void *ptr) } void -__vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, - vlist_update_cb update, int offset) +vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update) { - tree->key_offset = offset; tree->update = update; tree->version = 1; @@ -28,11 +26,10 @@ vlist_delete(struct vlist_tree *tree, struct vlist_node *node) } void -vlist_add(struct vlist_tree *tree, struct vlist_node *node) +vlist_add(struct vlist_tree *tree, struct vlist_node *node, void *key) { struct vlist_node *old_node = NULL; struct avl_node *anode; - void *key = (char *) node + tree->key_offset; node->avl.key = key; node->version = tree->version; @@ -26,7 +26,6 @@ struct vlist_tree { struct avl_tree avl; vlist_update_cb update; - int key_offset; bool keep_old; bool no_delete; @@ -38,10 +37,7 @@ struct vlist_node { int version; }; -void __vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update, int offset); - -#define vlist_init(tree, cmp, update, type, node, key) \ - __vlist_init(tree, cmp, update, offsetof(type, key) - offsetof(type, node)) +void vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update); #define vlist_find(tree, name, element, node_member) \ avl_find_element(&(tree)->avl, name, element, node_member.avl) @@ -51,7 +47,7 @@ static inline void vlist_update(struct vlist_tree *tree) tree->version++; } -void vlist_add(struct vlist_tree *tree, struct vlist_node *node); +void vlist_add(struct vlist_tree *tree, struct vlist_node *node, void *key); void vlist_delete(struct vlist_tree *tree, struct vlist_node *node); void vlist_flush(struct vlist_tree *tree); void vlist_flush_all(struct vlist_tree *tree); |