#define __LL_H
#include <libubox/avl.h>
+#include <netinet/in.h>
struct device;
struct device_hotplug_ops;
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
#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)
#ifndef __NETIFD_INTERFACE_H
#define __NETIFD_INTERFACE_H
-#include <netinet/in.h>
#include "device.h"
struct interface;
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
*/
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);
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)) {
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;
}
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 {
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