return STC_ERROR_NONE;
}
- static gboolean __rstn_counter_update_foreach_classid(gpointer key,
- gpointer value,
- gpointer data)
+static gboolean __process_contr_reply(GIOChannel *source,
+ GIOCondition condition,
+ gpointer user_data);
+
+static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
+{
+ GIOChannel *gio = NULL;
+ ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
+
+ /* close netlink socket for updating kernel counters */
+ if (system->contr_sock != -1) {
+ close(system->contr_sock);
+ system->contr_sock = -1;
+ }
+
+ if (system->contr_gsource_id != 0) {
+ g_source_remove(system->contr_gsource_id);
+ system->contr_gsource_id = 0;
+ }
+
+ /* create netlink socket for updating kernel counters */
+ system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
+ if (!(system->contr_sock)) {
+ STC_LOGE("failed to open socket");
+ FREE(system);
+ return STC_ERROR_FAIL;
+ }
+
+ gio = g_io_channel_unix_new(system->contr_sock);
+ system->contr_gsource_id =
+ g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
+ (GIOFunc) __process_contr_reply,
+ NULL);
+ g_io_channel_unref(gio);
+
+ return STC_ERROR_NONE;
+}
+
+ static gboolean __rstn_counter_update(stc_rstn_key_s *rstn_key,
+ stc_rstn_value_s *rstn_value,
+ classid_bytes_context_s *context)
{
- stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
- stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
- classid_bytes_context_s *context = (classid_bytes_context_s *)data;
-
- if (context->counter->intend != NFACCT_COUNTER)
- goto try_next_callback;
-
- if (rstn_value->classid != context->counter->classid)
- goto try_next_callback;
-
- if (rstn_value->data_limit_reached == TRUE) {
- context->data_limit_reached = TRUE;
- goto try_next_callback;
- }
-
switch (context->counter->iotype) {
case NFACCT_COUNTER_IN:
case NFACCT_COUNTER_OUT: