move interface address handling to the device module, clean up arguments to system_...
authorFelix Fietkau <nbd@openwrt.org>
Mon, 2 May 2011 21:00:30 +0000 (23:00 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 2 May 2011 21:00:30 +0000 (23:00 +0200)
device.h
interface-ip.c
interface.h
proto-static.c
system-dummy.c
system.h

index bbb78d8..0f8d382 100644 (file)
--- a/device.h
+++ b/device.h
@@ -2,6 +2,7 @@
 #define __LL_H
 
 #include <libubox/avl.h>
 #define __LL_H
 
 #include <libubox/avl.h>
+#include <netinet/in.h>
 
 struct device;
 struct device_hotplug_ops;
 
 struct device;
 struct device_hotplug_ops;
@@ -22,6 +23,42 @@ enum {
        DEV_OPT_TXQUEUELEN      = (1 << 2)
 };
 
        DEV_OPT_TXQUEUELEN      = (1 << 2)
 };
 
+enum device_addr_flags {
+       /* address family for routes and addresses */
+       DEVADDR_INET4   = (0 << 0),
+       DEVADDR_INET6   = (1 << 0),
+       DEVADDR_FAMILY  = DEVADDR_INET4 | DEVADDR_INET6,
+
+       /* device route (no gateway) */
+       DEVADDR_DEVICE  = (1 << 1),
+};
+
+union if_addr {
+       struct in_addr in;
+       struct in6_addr in6;
+};
+
+struct device_addr {
+       struct list_head list;
+       void *ctx;
+
+       enum device_addr_flags flags;
+
+       unsigned int mask;
+       union if_addr addr;
+};
+
+struct device_route {
+       struct list_head list;
+       void *ctx;
+
+       enum device_addr_flags flags;
+
+       unsigned int mask;
+       union if_addr addr;
+       union if_addr nexthop;
+};
+
 /* 
  * link layer device. typically represents a linux network device.
  * can be used to support VLANs as well
 /* 
  * link layer device. typically represents a linux network device.
  * can be used to support VLANs as well
index 797be58..51f23ef 100644 (file)
@@ -9,35 +9,35 @@
 #include "ubus.h"
 #include "system.h"
 
 #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;
 
 {
        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);
                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);
+       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;
 
 {
        int family;
 
-       if (addr->flags & IFADDR_INET6)
+       if (addr->flags & DEVADDR_INET6)
                family = AF_INET6;
        else
                family = AF_INET;
 
        list_del(&addr->list);
                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)
 {
 }
 
 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 (ctx && addr->ctx != ctx)
 
        list_for_each_entry_safe(addr, tmp, &iface->address, list) {
                if (ctx && addr->ctx != ctx)
index e19d61d..2d13b48 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef __NETIFD_INTERFACE_H
 #define __NETIFD_INTERFACE_H
 
 #ifndef __NETIFD_INTERFACE_H
 #define __NETIFD_INTERFACE_H
 
-#include <netinet/in.h>
 #include "device.h"
 
 struct interface;
 #include "device.h"
 
 struct interface;
@@ -27,42 +26,6 @@ struct interface_error {
        const char *data[];
 };
 
        const char *data[];
 };
 
-enum interface_addr_flags {
-       /* address family for routes and addresses */
-       IFADDR_INET4    = (0 << 0),
-       IFADDR_INET6    = (1 << 0),
-       IFADDR_FAMILY   = IFADDR_INET4 | IFADDR_INET6,
-
-       /* device route (no gateway) */
-       IFADDR_DEVICE   = (1 << 1),
-};
-
-union if_addr {
-       struct in_addr in;
-       struct in6_addr in6;
-};
-
-struct interface_addr {
-       struct list_head list;
-       void *ctx;
-
-       enum interface_addr_flags flags;
-
-       unsigned int mask;
-       union if_addr addr;
-};
-
-struct interface_route {
-       struct list_head list;
-       void *ctx;
-
-       enum interface_addr_flags flags;
-
-       unsigned int mask;
-       union if_addr addr;
-       union if_addr nexthop;
-};
-
 /*
  * interface configuration
  */
 /*
  * interface configuration
  */
@@ -110,8 +73,8 @@ void interface_add_error(struct interface *iface, const char *subsystem,
 
 int interface_attach_bridge(struct interface *iface, struct uci_section *s);
 
 
 int interface_attach_bridge(struct interface *iface, struct uci_section *s);
 
-int interface_add_address(struct interface *iface, struct interface_addr *addr);
-void interface_del_address(struct interface *iface, struct interface_addr *addr);
+int interface_add_address(struct interface *iface, struct device_addr *addr);
+void interface_del_address(struct interface *iface, struct device_addr *addr);
 void interface_del_ctx_addr(struct interface *iface, void *ctx);
 
 void start_pending_interfaces(void);
 void interface_del_ctx_addr(struct interface *iface, void *ctx);
 
 void start_pending_interfaces(void);
index 3a36ec0..53e0ec8 100644 (file)
@@ -56,11 +56,11 @@ parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask)
 static bool
 parse_addr(struct static_proto_state *state, const char *str, bool v6, int mask)
 {
 static bool
 parse_addr(struct static_proto_state *state, const char *str, bool v6, int mask)
 {
-       struct interface_addr *addr;
+       struct device_addr *addr;
        int af = v6 ? AF_INET6 : AF_INET;
 
        addr = calloc(1, sizeof(*addr));
        int af = v6 ? AF_INET6 : AF_INET;
 
        addr = calloc(1, sizeof(*addr));
-       addr->flags = v6 ? IFADDR_INET6 : IFADDR_INET4;
+       addr->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
        addr->ctx = state;
        addr->mask = mask;
        if (!parse_ip_and_netmask(af, str, &addr->addr, &addr->mask)) {
        addr->ctx = state;
        addr->mask = mask;
        if (!parse_ip_and_netmask(af, str, &addr->addr, &addr->mask)) {
index 7e009ba..2d391df 100644 (file)
@@ -62,13 +62,13 @@ int system_if_check(struct device *dev)
        return 0;
 }
 
        return 0;
 }
 
-int system_add_address(struct device *dev, int family, void *addr, int prefixlen)
+int system_add_address(struct device *dev, struct device_addr *addr)
 {
 {
-       uint8_t *a = addr;
+       uint8_t *a = (uint8_t *) &addr->addr.in;
 
 
-       if (family == AF_INET) {
+       if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
                DPRINTF("ifconfig %s add %d.%d.%d.%d/%d\n",
                DPRINTF("ifconfig %s add %d.%d.%d.%d/%d\n",
-                       dev->ifname, a[0], a[1], a[2], a[3], prefixlen);
+                       dev->ifname, a[0], a[1], a[2], a[3], addr->mask);
        } else {
                return -1;
        }
        } else {
                return -1;
        }
@@ -76,11 +76,11 @@ int system_add_address(struct device *dev, int family, void *addr, int prefixlen
        return 0;
 }
 
        return 0;
 }
 
-int system_del_address(struct device *dev, int family, void *addr)
+int system_del_address(struct device *dev, struct device_addr *addr)
 {
 {
-       uint8_t *a = addr;
+       uint8_t *a = (uint8_t *) &addr->addr.in;
 
 
-       if (family == AF_INET) {
+       if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
                DPRINTF("ifconfig %s del %d.%d.%d.%d\n",
                        dev->ifname, a[0], a[1], a[2], a[3]);
        } else {
                DPRINTF("ifconfig %s del %d.%d.%d.%d\n",
                        dev->ifname, a[0], a[1], a[2], a[3]);
        } else {
index 35f0971..3364151 100644 (file)
--- a/system.h
+++ b/system.h
@@ -16,7 +16,7 @@ int system_if_up(struct device *dev);
 int system_if_down(struct device *dev);
 int system_if_check(struct device *dev);
 
 int system_if_down(struct device *dev);
 int system_if_check(struct device *dev);
 
-int system_add_address(struct device *dev, int family, void *addr, int prefixlen);
-int system_del_address(struct device *dev, int family, void *addr);
+int system_add_address(struct device *dev, struct device_addr *addr);
+int system_del_address(struct device *dev, struct device_addr *addr);
 
 #endif
 
 #endif