mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-01-28 01:27:16 +01:00
Fix schedule inform and session handling
This commit is contained in:
parent
1e2ffebf65
commit
79871c5365
5 changed files with 69 additions and 2 deletions
|
|
@ -211,6 +211,7 @@ typedef struct cwmp {
|
|||
bool cwmp_periodic_enable;
|
||||
bool custom_notify_active;
|
||||
struct ubus_event_handler *ev;
|
||||
struct ubus_event_handler *intf_ev;
|
||||
bool throttle_session_triggered;
|
||||
enum firewall_cr_policy cr_policy;
|
||||
bool acs_changed;
|
||||
|
|
|
|||
|
|
@ -301,8 +301,10 @@ void cwmp_exit()
|
|||
uloop_timeout_cancel(&session_timer);
|
||||
uloop_timeout_cancel(&heartbeat_session_timer);
|
||||
clean_autonomous_complpolicy();
|
||||
clean_interface_update();
|
||||
clean_du_uuid_list();
|
||||
FREE(cwmp_main->ev);
|
||||
FREE(cwmp_main->intf_ev);
|
||||
uloop_end();
|
||||
shutdown(cwmp_main->cr_socket_desc, SHUT_RDWR);
|
||||
FREE(global_session_event);
|
||||
|
|
@ -344,6 +346,9 @@ int main(int argc, char **argv)
|
|||
if (0 != initiate_autonomous_complpolicy())
|
||||
return error;
|
||||
|
||||
if (0 != initiate_interface_update())
|
||||
return error;
|
||||
|
||||
trigger_cwmp_session_timer();
|
||||
|
||||
intiate_heartbeat_procedures();
|
||||
|
|
|
|||
|
|
@ -440,7 +440,7 @@ void start_cwmp_session(void)
|
|||
void trigger_cwmp_session_timer()
|
||||
{
|
||||
uloop_timeout_cancel(&retry_session_timer);
|
||||
uloop_timeout_set(&session_timer, 10);
|
||||
uloop_timeout_set(&session_timer, 500);
|
||||
}
|
||||
|
||||
void trigger_cwmp_throttle_session_timer(unsigned int delay)
|
||||
|
|
@ -491,6 +491,8 @@ void cwmp_schedule_session_with_event(struct uloop_timeout *timeout)
|
|||
cwmp_main->session->session_status.next_heartbeat = false;
|
||||
cwmp_main->session->session_status.is_heartbeat = true;
|
||||
cwmp_add_event_container(EVENT_IDX_14HEARTBEAT, "");
|
||||
start_cwmp_session();
|
||||
return;
|
||||
} else if (session_event->event == EVENT_IDX_10AUTONOMOUS_TRANSFER_COMPLETE) {
|
||||
auto_transfer_complete *auto_trnsfr_complete = (auto_transfer_complete *)session_event->extra_data;
|
||||
cwmp_root_cause_autonomous_transfer_complete(auto_trnsfr_complete);
|
||||
|
|
@ -507,7 +509,7 @@ void cwmp_schedule_session_with_event(struct uloop_timeout *timeout)
|
|||
cwmp_save_event_container(event_container);
|
||||
}
|
||||
|
||||
start_cwmp_session();
|
||||
trigger_cwmp_session_timer();
|
||||
}
|
||||
|
||||
static void cwmp_periodic_session_timer(struct uloop_timeout *timeout __attribute__((unused)))
|
||||
|
|
|
|||
|
|
@ -35,6 +35,38 @@ static const char *arr_session_status[] = {
|
|||
[SESSION_SUCCESS] = "success",
|
||||
};
|
||||
|
||||
|
||||
static void interface_update_handler(struct ubus_context *ctx __attribute__((unused)),
|
||||
struct ubus_event_handler *ev __attribute__((unused)),
|
||||
const char *type __attribute__((unused)), struct blob_attr *msg)
|
||||
{
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
const struct blobmsg_policy p[2] = {
|
||||
{ "interface", BLOBMSG_TYPE_STRING },
|
||||
{ "action", BLOBMSG_TYPE_STRING },
|
||||
};
|
||||
|
||||
struct blob_attr *tb[2] = {NULL};
|
||||
blobmsg_parse(p, 2, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if (!tb[0] || !tb[1])
|
||||
return;
|
||||
|
||||
const char *intf_name = blobmsg_get_string(tb[0]);
|
||||
const char *intf_up = blobmsg_get_string(tb[1]);
|
||||
|
||||
if (CWMP_STRCMP(intf_up, "ifup") != 0 || CWMP_STRCMP(cwmp_main->conf.default_wan_iface, intf_name) != 0)
|
||||
return;
|
||||
|
||||
/* If the last session was failure then schedule a session */
|
||||
if (cwmp_main->session->session_status.last_status == SESSION_FAILURE) {
|
||||
CWMP_LOG(INFO, "Schedule session for interface_update on %s, since last session was failure", intf_name);
|
||||
trigger_cwmp_session_timer();
|
||||
}
|
||||
}
|
||||
|
||||
static int reload_cmd(struct blob_buf *b)
|
||||
{
|
||||
CWMP_LOG(INFO, "triggered ubus reload");
|
||||
|
|
@ -446,3 +478,28 @@ void clean_autonomous_complpolicy(void)
|
|||
|
||||
ubus_unregister_event_handler(ubus_ctx, cwmp_main->ev);
|
||||
}
|
||||
|
||||
int initiate_interface_update(void)
|
||||
{
|
||||
cwmp_main->intf_ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler));
|
||||
if (cwmp_main->intf_ev == NULL)
|
||||
return -1;
|
||||
|
||||
CWMP_MEMSET(cwmp_main->intf_ev, 0, sizeof(struct ubus_event_handler));
|
||||
cwmp_main->intf_ev->cb = interface_update_handler;
|
||||
|
||||
int ret = ubus_register_event_handler(ubus_ctx, cwmp_main->intf_ev, "network.interface");
|
||||
if (ret) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void clean_interface_update(void)
|
||||
{
|
||||
if (cwmp_main->intf_ev == NULL)
|
||||
return;
|
||||
|
||||
ubus_unregister_event_handler(ubus_ctx, cwmp_main->intf_ev);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,4 +25,6 @@ int icwmp_uloop_ubus_init();
|
|||
void icwmp_uloop_ubus_exit();
|
||||
int initiate_autonomous_complpolicy(void);
|
||||
void clean_autonomous_complpolicy(void);
|
||||
int initiate_interface_update(void);
|
||||
void clean_interface_update(void);
|
||||
#endif /* __ICWMP_UBUS_UTILS_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue