diff mbox

[LEDE-DEV,netifd] ubus: add interface method to trigger renew event

Message ID 4006035d56380d0f2e41199e248de63e7971dceb.1492019597.git.mschiffer@universe-factory.net
State Accepted
Headers show

Commit Message

Matthias Schiffer April 12, 2017, 5:53 p.m. UTC
Not all topology or connectivity changes may be detected by netifd,
depending on the underlying technology (e.g. VPN software); this adds a way
to explicitly trigger a renew.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
---
 interface.c |  9 +++++++++
 interface.h |  1 +
 ubus.c      | 14 ++++++++++++++
 3 files changed, 24 insertions(+)

Comments

Hans Dedecker April 13, 2017, 10:11 a.m. UTC | #1
On Wed, Apr 12, 2017 at 7:53 PM, Matthias Schiffer
<mschiffer@universe-factory.net> wrote:
> Not all topology or connectivity changes may be detected by netifd,
> depending on the underlying technology (e.g. VPN software); this adds a way
> to explicitly trigger a renew.
>
> Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
> ---
>  interface.c |  9 +++++++++
>  interface.h |  1 +
>  ubus.c      | 14 ++++++++++++++
>  3 files changed, 24 insertions(+)
>
> diff --git a/interface.c b/interface.c
> index f150f7d..593b049 100644
> --- a/interface.c
> +++ b/interface.c
> @@ -1076,6 +1076,15 @@ interface_set_down(struct interface *iface)
>         return 0;
>  }
>
> +int
> +interface_renew(struct interface *iface)
> +{
> +       if (iface->state == IFS_TEARDOWN || iface->state == IFS_DOWN)
> +               return -1;
> +
> +       return interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
> +}
> +
>  void
>  interface_start_pending(void)
>  {
> diff --git a/interface.h b/interface.h
> index 1472324..d35fd98 100644
> --- a/interface.h
> +++ b/interface.h
> @@ -184,6 +184,7 @@ void interface_set_available(struct interface *iface, bool new_state);
>  int interface_set_up(struct interface *iface);
>  int interface_set_down(struct interface *iface);
>  void __interface_set_down(struct interface *iface, bool force);
> +int interface_renew(struct interface *iface);
>
>  void interface_set_main_dev(struct interface *iface, struct device *dev);
>  void interface_set_l3_dev(struct interface *iface, struct device *dev);
> diff --git a/ubus.c b/ubus.c
> index 945eca1..6f7c3e1 100644
> --- a/ubus.c
> +++ b/ubus.c
> @@ -378,6 +378,19 @@ netifd_handle_down(struct ubus_context *ctx, struct ubus_object *obj,
>         return 0;
>  }
>
> +static int
> +netifd_handle_renew(struct ubus_context *ctx, struct ubus_object *obj,
> +                  struct ubus_request_data *req, const char *method,
> +                  struct blob_attr *msg)
> +{
> +       struct interface *iface;
> +
> +       iface = container_of(obj, struct interface, ubus);
> +       interface_renew(iface);
> +
> +       return 0;
> +}
> +
>  static void
>  netifd_add_interface_errors(struct blob_buf *b, struct interface *iface)
>  {
> @@ -914,6 +927,7 @@ netifd_handle_set_data(struct ubus_context *ctx, struct ubus_object *obj,
>  static struct ubus_method iface_object_methods[] = {
>         { .name = "up", .handler = netifd_handle_up },
>         { .name = "down", .handler = netifd_handle_down },
> +       { .name = "renew", .handler = netifd_handle_renew },
>         { .name = "status", .handler = netifd_handle_status },
>         { .name = "prepare", .handler = netifd_handle_iface_prepare },
>         { .name = "dump", .handler = netifd_handle_dump },
> --
> 2.12.2
>
diff mbox

Patch

diff --git a/interface.c b/interface.c
index f150f7d..593b049 100644
--- a/interface.c
+++ b/interface.c
@@ -1076,6 +1076,15 @@  interface_set_down(struct interface *iface)
 	return 0;
 }
 
+int
+interface_renew(struct interface *iface)
+{
+	if (iface->state == IFS_TEARDOWN || iface->state == IFS_DOWN)
+		return -1;
+
+	return interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
+}
+
 void
 interface_start_pending(void)
 {
diff --git a/interface.h b/interface.h
index 1472324..d35fd98 100644
--- a/interface.h
+++ b/interface.h
@@ -184,6 +184,7 @@  void interface_set_available(struct interface *iface, bool new_state);
 int interface_set_up(struct interface *iface);
 int interface_set_down(struct interface *iface);
 void __interface_set_down(struct interface *iface, bool force);
+int interface_renew(struct interface *iface);
 
 void interface_set_main_dev(struct interface *iface, struct device *dev);
 void interface_set_l3_dev(struct interface *iface, struct device *dev);
diff --git a/ubus.c b/ubus.c
index 945eca1..6f7c3e1 100644
--- a/ubus.c
+++ b/ubus.c
@@ -378,6 +378,19 @@  netifd_handle_down(struct ubus_context *ctx, struct ubus_object *obj,
 	return 0;
 }
 
+static int
+netifd_handle_renew(struct ubus_context *ctx, struct ubus_object *obj,
+		   struct ubus_request_data *req, const char *method,
+		   struct blob_attr *msg)
+{
+	struct interface *iface;
+
+	iface = container_of(obj, struct interface, ubus);
+	interface_renew(iface);
+
+	return 0;
+}
+
 static void
 netifd_add_interface_errors(struct blob_buf *b, struct interface *iface)
 {
@@ -914,6 +927,7 @@  netifd_handle_set_data(struct ubus_context *ctx, struct ubus_object *obj,
 static struct ubus_method iface_object_methods[] = {
 	{ .name = "up", .handler = netifd_handle_up },
 	{ .name = "down", .handler = netifd_handle_down },
+	{ .name = "renew", .handler = netifd_handle_renew },
 	{ .name = "status", .handler = netifd_handle_status },
 	{ .name = "prepare", .handler = netifd_handle_iface_prepare },
 	{ .name = "dump", .handler = netifd_handle_dump },