use list_add_tail instead of list_add
[project/netifd.git] / interface-ip.c
index 20df281..2a26a4a 100644 (file)
@@ -9,40 +9,60 @@
 #include "ubus.h"
 #include "system.h"
 
-int interface_add_address(struct interface *iface, struct interface_addr *addr)
+int interface_add_address(struct interface *iface, struct device_addr *addr)
 {
        int family;
 
-       if (addr->flags & IFADDR_INET6)
+       if (addr->flags & DEVADDR_INET6)
                family = AF_INET6;
        else
                family = AF_INET;
 
-       list_add(&addr->list, &iface->address);
-       return system_add_address(iface->l3_iface->dev, family, &addr->addr.in, addr->mask);
+       list_add_tail(&addr->list, &iface->address);
+       return system_add_address(iface->l3_iface->dev, addr);
 }
 
-void interface_del_address(struct interface *iface, struct interface_addr *addr)
+void interface_del_address(struct interface *iface, struct device_addr *addr)
 {
        int family;
 
-       if (addr->flags & IFADDR_INET6)
+       if (addr->flags & DEVADDR_INET6)
                family = AF_INET6;
        else
                family = AF_INET;
 
        list_del(&addr->list);
-       system_del_address(iface->l3_iface->dev, family, &addr->addr.in);
+       system_del_address(iface->l3_iface->dev, addr);
 }
 
 void interface_del_ctx_addr(struct interface *iface, void *ctx)
 {
-       struct interface_addr *addr, *tmp;
+       struct device_addr *addr, *tmp;
 
        list_for_each_entry_safe(addr, tmp, &iface->address, list) {
-               if (addr->ctx != ctx)
+               if (ctx && addr->ctx != ctx)
                        continue;
 
                interface_del_address(iface, addr);
        }
 }
+
+int interface_add_route(struct interface *iface, struct device_route *route)
+{
+       list_add_tail(&route->list, &iface->routes);
+       return system_add_route(iface->l3_iface->dev, route);
+}
+
+void interface_del_route(struct interface *iface, struct device_route *route)
+{
+       list_del(&route->list);
+       system_del_route(iface->l3_iface->dev, route);
+}
+
+void interface_del_all_routes(struct interface *iface)
+{
+       struct device_route *route, *tmp;
+
+       list_for_each_entry_safe(route, tmp, &iface->routes, list)
+               interface_del_route(iface, route);
+}