[LEDE-DEV,netifd] interface: add new "ifup-failed" hotplug event

Message ID 1490941899-2841-1-git-send-email-ms@dev.tdt.de
State Accepted
Headers show

Commit Message

Martin Schiller March 31, 2017, 6:31 a.m.
This hook makes it possible to do some helper work in hotplug scripts
when a connection is not established successfully.

example: try several username/passwords from a pool to establish a
pppoe or wwan connection by replacing the configured values of the
connection in a hotplug script.

Signed-off-by: Martin Schiller <ms@dev.tdt.de>
---
 interface-event.c | 2 ++
 interface.c       | 4 ++++
 interface.h       | 1 +
 3 files changed, 7 insertions(+)

Comments

Martin Schiller May 5, 2017, 11:44 a.m. | #1
Are there any comments about this patch?
I still want to get this feature into netifd.

On 2017-03-31 08:31, Martin Schiller wrote:
> This hook makes it possible to do some helper work in hotplug scripts
> when a connection is not established successfully.
> 
> example: try several username/passwords from a pool to establish a
> pppoe or wwan connection by replacing the configured values of the
> connection in a hotplug script.
> 
> Signed-off-by: Martin Schiller <ms@dev.tdt.de>
> ---
>  interface-event.c | 2 ++
>  interface.c       | 4 ++++
>  interface.h       | 1 +
>  3 files changed, 7 insertions(+)
> 
> diff --git a/interface-event.c b/interface-event.c
> index 4976c2c..86e8f54 100644
> --- a/interface-event.c
> +++ b/interface-event.c
> @@ -33,6 +33,7 @@ static struct uloop_process task = {
>  static const char * const eventnames[] = {
>  	[IFEV_DOWN] = "ifdown",
>  	[IFEV_UP] = "ifup",
> +	[IFEV_UP_FAILED] = "ifup-failed",
>  	[IFEV_UPDATE] = "ifupdate",
>  	[IFEV_FREE] = "free",
>  	[IFEV_RELOAD] = "reload",
> @@ -191,6 +192,7 @@ static void interface_event_cb(struct
> interface_user *dep, struct interface *ifa
>  	switch (ev) {
>  		case IFEV_LINK_UP:
>  		case IFEV_UP:
> +		case IFEV_UP_FAILED:
>  		case IFEV_UPDATE:
>  		case IFEV_DOWN:
>  			interface_queue_event(iface, ev);
> diff --git a/interface.c b/interface.c
> index f150f7d..e04d477 100644
> --- a/interface.c
> +++ b/interface.c
> @@ -241,6 +241,7 @@ interface_event(struct interface *iface, enum
> interface_event ev)
>  		adev = iface->l3_dev.dev;
>  		/* fall through */
>  	case IFEV_DOWN:
> +	case IFEV_UP_FAILED:
>  		alias_notify_device(iface->name, adev);
>  		break;
>  	default:
> @@ -268,6 +269,8 @@ mark_interface_down(struct interface *iface)
>  	iface->state = IFS_DOWN;
>  	if (state == IFS_UP)
>  		interface_event(iface, IFEV_DOWN);
> +	else
> +		interface_event(iface, IFEV_UP_FAILED);
>  	interface_ip_set_enabled(&iface->config_ip, false);
>  	interface_ip_set_enabled(&iface->proto_ip, false);
>  	interface_ip_flush(&iface->proto_ip);
> @@ -557,6 +560,7 @@ interface_alias_cb(struct interface_user *dep,
> struct interface *iface, enum int
>  		interface_set_available(alias, true);
>  		break;
>  	case IFEV_DOWN:
> +	case IFEV_UP_FAILED:
>  		interface_set_available(alias, false);
>  		interface_set_main_dev(alias, NULL);
>  		break;
> diff --git a/interface.h b/interface.h
> index 1472324..c51705c 100644
> --- a/interface.h
> +++ b/interface.h
> @@ -23,6 +23,7 @@ struct interface_proto_state;
>  enum interface_event {
>  	IFEV_DOWN,
>  	IFEV_UP,
> +	IFEV_UP_FAILED,
>  	IFEV_UPDATE,
>  	IFEV_FREE,
>  	IFEV_RELOAD,
Jo-Philipp Wich May 6, 2017, 12:47 p.m. | #2
Hi,

> Are there any comments about this patch?

can't you achieve the same by simply watching ifdown events and checking
ifstatus/devstatus indicators?

~ Jo
Martin Schiller May 8, 2017, 4:12 a.m. | #3
On 2017-05-06 14:47, Jo-Philipp Wich wrote:
> Hi,
> 
>> Are there any comments about this patch?
> 
> can't you achieve the same by simply watching ifdown events and 
> checking
> ifstatus/devstatus indicators?

No, unfortunately not. An ifdown event is only generated when the 
interface has already been up:

https://git.lede-project.org/?p=project/netifd.git;a=blob;f=interface.c;h=593b0490c85d8cc30dd338979aaea6b560e50866;hb=HEAD#l269

So, in a situation where a interface can't be established (e.g. wrong 
username/password) there won't be any event.

Patch

diff --git a/interface-event.c b/interface-event.c
index 4976c2c..86e8f54 100644
--- a/interface-event.c
+++ b/interface-event.c
@@ -33,6 +33,7 @@  static struct uloop_process task = {
 static const char * const eventnames[] = {
 	[IFEV_DOWN] = "ifdown",
 	[IFEV_UP] = "ifup",
+	[IFEV_UP_FAILED] = "ifup-failed",
 	[IFEV_UPDATE] = "ifupdate",
 	[IFEV_FREE] = "free",
 	[IFEV_RELOAD] = "reload",
@@ -191,6 +192,7 @@  static void interface_event_cb(struct interface_user *dep, struct interface *ifa
 	switch (ev) {
 		case IFEV_LINK_UP:
 		case IFEV_UP:
+		case IFEV_UP_FAILED:
 		case IFEV_UPDATE:
 		case IFEV_DOWN:
 			interface_queue_event(iface, ev);
diff --git a/interface.c b/interface.c
index f150f7d..e04d477 100644
--- a/interface.c
+++ b/interface.c
@@ -241,6 +241,7 @@  interface_event(struct interface *iface, enum interface_event ev)
 		adev = iface->l3_dev.dev;
 		/* fall through */
 	case IFEV_DOWN:
+	case IFEV_UP_FAILED:
 		alias_notify_device(iface->name, adev);
 		break;
 	default:
@@ -268,6 +269,8 @@  mark_interface_down(struct interface *iface)
 	iface->state = IFS_DOWN;
 	if (state == IFS_UP)
 		interface_event(iface, IFEV_DOWN);
+	else
+		interface_event(iface, IFEV_UP_FAILED);
 	interface_ip_set_enabled(&iface->config_ip, false);
 	interface_ip_set_enabled(&iface->proto_ip, false);
 	interface_ip_flush(&iface->proto_ip);
@@ -557,6 +560,7 @@  interface_alias_cb(struct interface_user *dep, struct interface *iface, enum int
 		interface_set_available(alias, true);
 		break;
 	case IFEV_DOWN:
+	case IFEV_UP_FAILED:
 		interface_set_available(alias, false);
 		interface_set_main_dev(alias, NULL);
 		break;
diff --git a/interface.h b/interface.h
index 1472324..c51705c 100644
--- a/interface.h
+++ b/interface.h
@@ -23,6 +23,7 @@  struct interface_proto_state;
 enum interface_event {
 	IFEV_DOWN,
 	IFEV_UP,
+	IFEV_UP_FAILED,
 	IFEV_UPDATE,
 	IFEV_FREE,
 	IFEV_RELOAD,