projects
/
project
/
netifd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
system-linux: fix a glob related memleak
[project/netifd.git]
/
interface.c
diff --git
a/interface.c
b/interface.c
index
b0fe9de
..
4543250
100644
(file)
--- a/
interface.c
+++ b/
interface.c
@@
-272,11
+272,14
@@
interface_check_state(struct interface *iface)
switch (iface->state) {
case IFS_UP:
if (!iface->enabled || !link_state) {
switch (iface->state) {
case IFS_UP:
if (!iface->enabled || !link_state) {
- mark_interface_down(iface);
interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, false);
interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, false);
+ mark_interface_down(iface);
}
break;
case IFS_DOWN:
}
break;
case IFS_DOWN:
+ if (!iface->available)
+ return;
+
if (iface->autostart && iface->enabled && link_state && !config_init)
__interface_set_up(iface);
break;
if (iface->autostart && iface->enabled && link_state && !config_init)
__interface_set_up(iface);
break;
@@
-308,6
+311,13
@@
interface_set_link_state(struct interface *iface, bool new_state)
}
static void
}
static void
+interface_ext_cb(struct device_user *dep, enum device_event ev)
+{
+ if (ev == DEV_EVENT_REMOVE)
+ device_remove_user(dep);
+}
+
+static void
interface_cb(struct device_user *dep, enum device_event ev)
{
struct interface *iface;
interface_cb(struct device_user *dep, enum device_event ev)
{
struct interface *iface;
@@
-329,7
+339,7
@@
interface_cb(struct device_user *dep, enum device_event ev)
break;
case DEV_EVENT_LINK_UP:
new_state = true;
break;
case DEV_EVENT_LINK_UP:
new_state = true;
-
case DEV_EVENT_LINK_DOWN:
+ case DEV_EVENT_LINK_DOWN:
interface_set_link_state(iface, new_state);
break;
case DEV_EVENT_TOPO_CHANGE:
interface_set_link_state(iface, new_state);
break;
case DEV_EVENT_TOPO_CHANGE:
@@
-491,6
+501,10
@@
interface_claim_device(struct interface *iface)
} else if (iface->ifname &&
!(iface->proto_handler->flags & PROTO_FLAG_NODEV)) {
dev = device_get(iface->ifname, true);
} else if (iface->ifname &&
!(iface->proto_handler->flags & PROTO_FLAG_NODEV)) {
dev = device_get(iface->ifname, true);
+ if (dev && dev->default_config && iface->device_config)
+ device_set_config(dev, dev->type, iface->config);
+ } else {
+ dev = iface->ext_dev.dev;
}
if (dev)
}
if (dev)
@@
-509,8
+523,8
@@
interface_cleanup_state(struct interface *iface)
interface_clear_errors(iface);
interface_set_proto_state(iface, NULL);
interface_clear_errors(iface);
interface_set_proto_state(iface, NULL);
- i
f (iface->main_dev.dev)
-
interface_set_main
_dev(iface, NULL);
+ i
nterface_set_main_dev(iface, NULL);
+
interface_set_l3
_dev(iface, NULL);
}
static void
}
static void
@@
-518,6
+532,9
@@
interface_cleanup(struct interface *iface)
{
struct interface_user *dep, *tmp;
{
struct interface_user *dep, *tmp;
+ uloop_timeout_cancel(&iface->remove_timer);
+ device_remove_user(&iface->ext_dev);
+
if (iface->parent_iface.iface)
interface_remove_user(&iface->parent_iface);
if (iface->parent_iface.iface)
interface_remove_user(&iface->parent_iface);
@@
-641,6
+658,7
@@
interface_alloc(const char *name, struct blob_attr *config)
struct blob_attr *cur;
const char *proto_name = NULL;
char *iface_name;
struct blob_attr *cur;
const char *proto_name = NULL;
char *iface_name;
+ bool force_link = false;
iface = calloc_a(sizeof(*iface), &iface_name, strlen(name) + 1);
iface->name = strcpy(iface_name, name);
iface = calloc_a(sizeof(*iface), &iface_name, strlen(name) + 1);
iface->name = strcpy(iface_name, name);
@@
-653,6
+671,7
@@
interface_alloc(const char *name, struct blob_attr *config)
iface->config_ip.enabled = false;
iface->main_dev.cb = interface_cb;
iface->config_ip.enabled = false;
iface->main_dev.cb = interface_cb;
+ iface->ext_dev.cb = interface_ext_cb;
blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
blob_data(config), blob_len(config));
blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
blob_data(config), blob_len(config));
@@
-661,9
+680,11
@@
interface_alloc(const char *name, struct blob_attr *config)
proto_name = blobmsg_data(cur);
proto_attach_interface(iface, proto_name);
proto_name = blobmsg_data(cur);
proto_attach_interface(iface, proto_name);
+ if (iface->proto_handler->flags & PROTO_FLAG_FORCE_LINK_DEFAULT)
+ force_link = true;
iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true);
iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true);
- iface->force_link = blobmsg_get_bool_default(tb[IFACE_ATTR_FORCE_LINK], f
alse
);
+ iface->force_link = blobmsg_get_bool_default(tb[IFACE_ATTR_FORCE_LINK], f
orce_link
);
iface->proto_ip.no_defaultroute =
!blobmsg_get_bool_default(tb[IFACE_ATTR_DEFAULTROUTE], true);
iface->proto_ip.no_dns =
iface->proto_ip.no_defaultroute =
!blobmsg_get_bool_default(tb[IFACE_ATTR_DEFAULTROUTE], true);
iface->proto_ip.no_dns =
@@
-709,6
+730,7
@@
interface_alloc(const char *name, struct blob_attr *config)
void interface_set_dynamic(struct interface *iface)
{
iface->dynamic = true;
void interface_set_dynamic(struct interface *iface)
{
iface->dynamic = true;
+ iface->autostart = true;
iface->node.version = -1; // Don't delete on reload
}
iface->node.version = -1; // Don't delete on reload
}
@@
-806,6
+828,9
@@
interface_remove_link(struct interface *iface, struct device *dev)
if (mdev && mdev->hotplug_ops)
return mdev->hotplug_ops->del(mdev, dev);
if (mdev && mdev->hotplug_ops)
return mdev->hotplug_ops->del(mdev, dev);
+ if (dev == iface->ext_dev.dev)
+ device_remove_user(&iface->ext_dev);
+
if (!iface->main_dev.hotplug)
return UBUS_STATUS_INVALID_ARGUMENT;
if (!iface->main_dev.hotplug)
return UBUS_STATUS_INVALID_ARGUMENT;
@@
-816,8
+841,8
@@
interface_remove_link(struct interface *iface, struct device *dev)
return 0;
}
return 0;
}
-int
-interface_add_link(struct interface *iface, struct device *dev)
+
static
int
+interface_add_link(struct interface *iface, struct device *dev
, bool link_ext
)
{
struct device *mdev = iface->main_dev.dev;
{
struct device *mdev = iface->main_dev.dev;
@@
-834,20
+859,23
@@
interface_add_link(struct interface *iface, struct device *dev)
return UBUS_STATUS_NOT_SUPPORTED;
}
return UBUS_STATUS_NOT_SUPPORTED;
}
+ if (link_ext)
+ device_add_user(&iface->ext_dev, dev);
+
interface_set_main_dev(iface, dev);
iface->main_dev.hotplug = true;
return 0;
}
int
interface_set_main_dev(iface, dev);
iface->main_dev.hotplug = true;
return 0;
}
int
-interface_handle_link(struct interface *iface, const char *name, bool add)
+interface_handle_link(struct interface *iface, const char *name, bool add
, bool link_ext
)
{
struct device *dev;
int ret;
device_lock();
{
struct device *dev;
int ret;
device_lock();
- dev = device_get(name, add ?
2
: 0);
+ dev = device_get(name, add ?
(link_ext ? 2 : 1)
: 0);
if (!dev) {
ret = UBUS_STATUS_NOT_FOUND;
goto out;
if (!dev) {
ret = UBUS_STATUS_NOT_FOUND;
goto out;
@@
-855,11
+883,11
@@
interface_handle_link(struct interface *iface, const char *name, bool add)
if (add) {
device_set_present(dev, true);
if (add) {
device_set_present(dev, true);
- if (iface->device_config)
- device_set_config(dev,
&simple_device_
type, iface->config);
+ if (iface->device_config
&& dev->default_config
)
+ device_set_config(dev,
dev->
type, iface->config);
system_if_apply_settings(dev, &dev->settings, dev->settings.flags);
system_if_apply_settings(dev, &dev->settings, dev->settings.flags);
- ret = interface_add_link(iface, dev);
+ ret = interface_add_link(iface, dev
, link_ext
);
} else {
ret = interface_remove_link(iface, dev);
}
} else {
ret = interface_remove_link(iface, dev);
}