From: Felix Fietkau Date: Mon, 2 May 2011 21:00:30 +0000 (+0200) Subject: move interface address handling to the device module, clean up arguments to system_... X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=273550337f70b8b2175875e0c4f0bbd483cfe326;p=oweals%2Fnetifd.git move interface address handling to the device module, clean up arguments to system_{add,del}_addr --- diff --git a/device.h b/device.h index bbb78d8..0f8d382 100644 --- a/device.h +++ b/device.h @@ -2,6 +2,7 @@ #define __LL_H #include +#include struct device; struct device_hotplug_ops; @@ -22,6 +23,42 @@ enum { 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 diff --git a/interface-ip.c b/interface-ip.c index 797be58..51f23ef 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -9,35 +9,35 @@ #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); + 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 (ctx && addr->ctx != ctx) diff --git a/interface.h b/interface.h index e19d61d..2d13b48 100644 --- a/interface.h +++ b/interface.h @@ -1,7 +1,6 @@ #ifndef __NETIFD_INTERFACE_H #define __NETIFD_INTERFACE_H -#include #include "device.h" struct interface; @@ -27,42 +26,6 @@ struct interface_error { 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 */ @@ -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_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); diff --git a/proto-static.c b/proto-static.c index 3a36ec0..53e0ec8 100644 --- a/proto-static.c +++ b/proto-static.c @@ -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) { - struct interface_addr *addr; + struct device_addr *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)) { diff --git a/system-dummy.c b/system-dummy.c index 7e009ba..2d391df 100644 --- a/system-dummy.c +++ b/system-dummy.c @@ -62,13 +62,13 @@ int system_if_check(struct device *dev) 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", - 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; } @@ -76,11 +76,11 @@ int system_add_address(struct device *dev, int family, void *addr, int prefixlen 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 { diff --git a/system.h b/system.h index 35f0971..3364151 100644 --- 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_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