Ticket #15: openvpn_accounting.patch

File openvpn_accounting.patch, 22.9 KB (added by Emmanuel Bretelle, 14 years ago)

OpenVPN accounting patch

  • configure.ac

    From c985b48175071006a077c377cd23170f516c2036 Mon Sep 17 00:00:00 2001
    From: chantra <chantra@debuntu.org>
    Date: Sat, 5 Jun 2010 13:21:53 +0200
    Subject: Attempt to handle accounting in OpenVPN
    
    This might help setting Accounting info for
    Radius plugins.
    ref: http://comments.gmane.org/gmane.network.openvpn.devel/990
    Signed-off-by: chantra <chantra@debuntu.org>
    ---
     configure.ac     |   11 ++++++++
     init.c           |    5 ++++
     multi.c          |   68 ++++++++++++++++++++++++++++++++++++++++++++++++-----
     openvpn-plugin.h |    3 +-
     openvpn.h        |    5 ++++
     options.c        |   25 +++++++++++++++++++
     options.h        |    4 +++
     plugin.c         |    2 +
     8 files changed, 115 insertions(+), 8 deletions(-)
    
    diff --git a/configure.ac b/configure.ac
    index 4626e46..8c76e24 100644
    a b AC_ARG_ENABLE(profiling, 
    199199   [PROFILE="no"]
    200200)
    201201
     202AC_ARG_ENABLE(accounting,
     203   [  --enable-accounting     Enable client accounting support],
     204   [ACCOUNTING="$enableval"],
     205   [ACCOUNTING="no"]
     206)
     207
    202208AC_ARG_ENABLE(strict-options,
    203209   [  --enable-strict-options Enable strict options check between peers (debugging option)],
    204210   [STRICT_OPTIONS="$enableval"],
    if test "$PROFILE" = "yes"; then 
    858864   CFLAGS="$CFLAGS -pg -DENABLE_PROFILING"
    859865fi
    860866
     867dnl enable accounting
     868if test "$ACCOUNTING" = "yes"; then
     869   AC_DEFINE(ENABLE_ACCOUNTING, 1, [Enable client accounting])
     870fi
     871
    861872dnl enable strict options check between peers
    862873if test "$STRICT_OPTIONS" = "yes"; then
    863874   AC_DEFINE(STRICT_OPTIONS_CHECK, 1, [Enable strict options check between peers])
  • init.c

    diff --git a/init.c b/init.c
    index 8ec6ca6..5bb11ca 100644
    a b do_init_timers (struct context *c, bool deferred) 
    870870        event_timeout_init (&c->c2.occ_mtu_load_test_interval, OCC_MTU_LOAD_INTERVAL_SECONDS, now);
    871871#endif
    872872
     873#ifdef ENABLE_ACCOUNTING
     874      if (c->options.accounting_freq)
     875  event_timeout_init (&c->c2.accounting_interval, c->options.accounting_freq, now);
     876#endif
     877
    873878      /* initialize packet_id persistence timer */
    874879#ifdef USE_CRYPTO
    875880      if (c->options.packet_id_file)
  • multi.c

    diff --git a/multi.c b/multi.c
    index 7a06bd0..9d4c58d 100644
    a b multi_client_connect_post (struct multi_context *m, 
    13011301                             option_permissions_mask,
    13021302                             option_types_found,
    13031303                             mi->context.c2.es);
    1304 
    13051304      if (!delete_file (dc_file))
    13061305        msg (D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %s",
    13071306             dc_file);
    multi_client_connect_post (struct multi_context *m, 
    13141313       */
    13151314      multi_select_virtual_addr (m, mi);
    13161315      multi_set_virtual_addr_env (m, mi);
     1316#ifdef ENABLE_ACCOUNTING
     1317      event_timeout_modify_wakeup (&mi->context.c2.accounting_interval, mi->context.options.accounting_freq);
     1318#endif
     1319
    13171320    }
    13181321}
    13191322
    multi_client_connect_post_plugin (struct multi_context *m, 
    13411344        {
    13421345          if (config.list[i] && config.list[i]->value)
    13431346            options_string_import (&mi->context.options,
    1344                                    config.list[i]->value,
    1345                                    D_IMPORT_ERRORS|M_OPTERR,
    1346                                    option_permissions_mask,
    1347                                    option_types_found,
    1348                                    mi->context.c2.es);
     1347                                     config.list[i]->value,
     1348                                     D_IMPORT_ERRORS|M_OPTERR,
     1349                                     option_permissions_mask,
     1350                                     option_types_found,
     1351                                     mi->context.c2.es);
    13491352        }
    13501353
    13511354      /*
    multi_client_connect_post_plugin (struct multi_context *m, 
    13561359       */
    13571360      multi_select_virtual_addr (m, mi);
    13581361      multi_set_virtual_addr_env (m, mi);
     1362#ifdef ENABLE_ACCOUNTING
     1363        event_timeout_modify_wakeup (&mi->context.c2.accounting_interval, mi->context.options.accounting_freq);
     1364#endif
     1365
    13591366    }
    13601367}
    13611368
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    15201527
    15211528      /* do --client-connect setenvs */
    15221529      multi_client_connect_setenv (m, mi);
     1530#ifdef ENABLE_ACCOUNTING
     1531              event_timeout_modify_wakeup (&mi->context.c2.accounting_interval, mi->context.options.accounting_freq);
     1532#endif
     1533
    15231534
    15241535#ifdef ENABLE_PLUGIN
    15251536      /*
    multi_process_per_second_timers_dowork (struct multi_context *m) 
    23792390      if (status_trigger (m->top.c1.status_output))
    23802391        multi_print_status (m, m->top.c1.status_output, m->status_file_version);
    23812392    }
    2382 
     2393#ifdef ENABLE_PLUGIN
     2394#ifdef ENABLE_ACCOUNTING
     2395        /* for each client context if register to PLUGIN_STATS
     2396   * and event should be triggered, send status to plugin
     2397   */   
     2398  if (plugin_defined (m->top.plugins, OPENVPN_PLUGIN_STATS))
     2399    {
     2400      struct argv argv = argv_new ();
     2401      if (m->hash)
     2402        {
     2403          struct gc_arena gc_top = gc_new ();
     2404          struct hash_iterator hi;
     2405          const struct hash_element *he;
     2406   
     2407          hash_iterator_init (m->hash, &hi, true);
     2408          while ((he = hash_iterator_next (&hi)))
     2409           {
     2410             struct gc_arena gc = gc_new ();
     2411             struct multi_instance *mi = (struct multi_instance *) he->value;
     2412             if (!mi->halt)
     2413               {
     2414                 struct context *client_context = &(mi->context);
     2415                 struct timeval null;
     2416                 CLEAR (null);
     2417                 if (event_timeout_trigger (&(client_context->c2.accounting_interval), &null, ETT_DEFAULT))
     2418                   {
     2419                     msg (M_DEBUG, "DEBUG: ACCOUNTING triggerred after %ds (%d) for %s",
     2420                                  client_context->options.accounting_freq, client_context->c2.accounting_interval.n,
     2421                              tls_common_name (client_context->c2.tls_multi, false));
     2422                     setenv_stats (client_context);
     2423                     if (plugin_call (client_context->plugins, OPENVPN_PLUGIN_STATS, &argv, NULL, client_context->c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
     2424                       {
     2425                         msg (M_WARN, "WARNING: stats plugin call failed");
     2426                       }
     2427                   }
     2428               }
     2429             gc_free (&gc);
     2430           }
     2431         hash_iterator_free (&hi);
     2432        }
     2433      argv_reset (&argv);
     2434    }
     2435#endif /* ENABLE_ACCOUNTING */
     2436#endif /* ENABLE_PLUGIN */
    23832437  /* possibly flush ifconfig-pool file */
    23842438  multi_ifconfig_pool_persist (m, false);
    23852439
  • openvpn-plugin.h

    diff --git a/openvpn-plugin.h b/openvpn-plugin.h
    index 56b0a70..bb5fd39 100644
    a b  
    9797#define OPENVPN_PLUGIN_CLIENT_CONNECT_V2     9
    9898#define OPENVPN_PLUGIN_TLS_FINAL             10
    9999#define OPENVPN_PLUGIN_ENABLE_PF             11
    100 #define OPENVPN_PLUGIN_N                     12
     100#define OPENVPN_PLUGIN_STATS                 12
     101#define OPENVPN_PLUGIN_N                     13
    101102
    102103/*
    103104 * Build a mask out of a set of plug-in types.
  • openvpn.h

    diff --git a/openvpn.h b/openvpn.h
    index 0757eb1..08f1b3d 100644
    a b struct context_2 
    305305  int occ_mtu_load_n_tries;
    306306#endif
    307307
     308#ifdef ENABLE_ACCOUNTING
     309  struct event_timeout accounting_interval;
     310#endif
     311
    308312#ifdef USE_CRYPTO
    309313
    310314  /*
    struct context_2 
    447451#ifdef MANAGEMENT_DEF_AUTH
    448452  struct man_def_auth_context mda_context;
    449453#endif
     454
    450455};
    451456
    452457/*
  • options.c

    diff --git a/options.c b/options.c
    index 3a2a6c5..bc04aa3 100644
    a b static const char usage_message[] = 
    307307  "--status file n : Write operational status to file every n seconds.\n"
    308308  "--status-version [n] : Choose the status file format version number.\n"
    309309  "                  Currently, n can be 1, 2, or 3 (default=1).\n"
     310#ifdef ENABLE_ACCOUNTING
     311  "--accounting-freq s : Send client accounting information every s seconds.\n"
     312#endif
    310313#ifdef ENABLE_OCC
    311314  "--disable-occ   : Disable options consistency check between peers.\n"
    312315#endif
    init_options (struct options *o, const bool init_gc) 
    691694#ifdef ENABLE_OCC
    692695  o->occ = true;
    693696#endif
     697#ifdef ENABLE_ACCOUNTING
     698  o->accounting_freq = 60;
     699#endif
    694700#ifdef ENABLE_MANAGEMENT
    695701  o->management_log_history_cache = 250;
    696702  o->management_echo_buffer_size = 100;
    show_settings (const struct options *o) 
    13821388  show_p2mp_parms (o);
    13831389#endif
    13841390
     1391#ifdef ENABLE_ACCOUNTING
     1392  SHOW_INT (accounting_freq);
     1393#endif
     1394
    13851395#ifdef WIN32
    13861396  SHOW_BOOL (show_net_up);
    13871397  SHOW_INT (route_method);
    add_option (struct options *options, 
    57415751      options->persist_mode = 1;
    57425752    }
    57435753#endif
     5754#ifdef ENABLE_ACCOUNTING
     5755  else if (streq (p[0], "accounting-freq") && p[1])
     5756    {
     5757      int freq;
     5758
     5759      VERIFY_PERMISSION (OPT_P_INSTANCE | OPT_P_GENERAL);
     5760      freq = atoi (p[1]);
     5761      if (freq < 0)
     5762  {
     5763    msg (msglevel, "--accounting-freq must be >= 0");
     5764    goto err;
     5765  }
     5766      options->accounting_freq = freq;
     5767    }
     5768#endif
    57445769  else
    57455770    {
    57465771      if (file)
  • options.h

    diff --git a/options.h b/options.h
    index ebff532..0f66f7a 100644
    a b struct options 
    405405
    406406#endif
    407407
     408#ifdef ENABLE_ACCOUNTING
     409  int accounting_freq;
     410#endif
     411
    408412#ifdef USE_CRYPTO
    409413  /* Cipher parms */
    410414  const char *shared_secret_file;
  • plugin.c

    diff --git a/plugin.c b/plugin.c
    index 769de8d..9d0563d 100644
    a b plugin_type_name (const int type) 
    8888      return "PLUGIN_TLS_FINAL";
    8989    case OPENVPN_PLUGIN_ENABLE_PF:
    9090      return "OPENVPN_PLUGIN_ENABLE_PF";
     91    case OPENVPN_PLUGIN_STATS:
     92      return "OPENVPN_PLUGIN_STATS";
    9193    default:
    9294      return "PLUGIN_???";
    9395    }
  • init.c

    -- 
    1.7.0.4
    
    
    From 213738abce4f30aa183c2bee59ac8c852e11ff3a Mon Sep 17 00:00:00 2001
    From: chantra <chantra@debuntu.org>
    Date: Sun, 6 Jun 2010 07:25:30 +0200
    Subject: OPENVPN_PLUGIN_ACCOUNTING can now update acct freq
    
    OPENVPN_PLUGIN_ACCOUNTING can make use of
    openvpn_plugin_func_v2 to update accounting_freq value
    
    Fixed issues:
     - handle option update with do_deferred_options
     - properly handle timeout modification/init/clear
     - check if timeout defined before checking if
       timeout can be triggered
    Signed-off-by: chantra <chantra@debuntu.org>
    ---
     init.c           |   18 ++++++++
     multi.c          |  125 ++++++++++++++++++++++++++++++++++++++----------------
     openvpn-plugin.h |    2 +-
     openvpn.h        |    2 +-
     options.c        |    2 +-
     options.h        |    3 +-
     plugin.c         |    4 +-
     7 files changed, 113 insertions(+), 43 deletions(-)
    
    diff --git a/init.c b/init.c
    index 5bb11ca..c60617d 100644
    a b do_deferred_options (struct context *c, const unsigned int found) 
    14311431    }
    14321432#endif
    14331433
     1434#if defined(ENABLE_PLUGIN) && defined(ENABLE_ACCOUNTING)
     1435  if (found & OPT_P_ACCOUNTING)
     1436    {
     1437      msg (D_PUSH, "OPTIONS IMPORT: accounting interval modified");
     1438      if (c->options.accounting_freq == 0)
     1439        {
     1440          if (event_timeout_defined (&c->c2.accounting_interval))
     1441            event_timeout_clear (&c->c2.accounting_interval);
     1442        }
     1443      else
     1444        {
     1445          if (event_timeout_defined (&c->c2.accounting_interval))
     1446            event_timeout_modify_wakeup( &c->c2.accounting_interval, c->options.accounting_freq);
     1447          else
     1448            event_timeout_init (&c->c2.accounting_interval, c->options.accounting_freq, now);
     1449        }
     1450    }
     1451#endif
    14341452  if (found & OPT_P_SHAPER)
    14351453    {
    14361454      msg (D_PUSH, "OPTIONS IMPORT: traffic shaper enabled");
  • multi.c

    diff --git a/multi.c b/multi.c
    index 9d4c58d..f6c70d9 100644
    a b multi_client_connect_post (struct multi_context *m, 
    13131313       */
    13141314      multi_select_virtual_addr (m, mi);
    13151315      multi_set_virtual_addr_env (m, mi);
    1316 #ifdef ENABLE_ACCOUNTING
    1317       event_timeout_modify_wakeup (&mi->context.c2.accounting_interval, mi->context.options.accounting_freq);
    1318 #endif
    13191316
    13201317    }
    13211318}
    multi_client_connect_post_plugin (struct multi_context *m, 
    13591356       */
    13601357      multi_select_virtual_addr (m, mi);
    13611358      multi_set_virtual_addr_env (m, mi);
     1359    }
     1360}
     1361
    13621362#ifdef ENABLE_ACCOUNTING
    1363         event_timeout_modify_wakeup (&mi->context.c2.accounting_interval, mi->context.options.accounting_freq);
    1364 #endif
     1363/*
     1364 * Called after stats plug-in is called
     1365 */
     1366static void
     1367multi_accounting_post_plugin (struct multi_context *m,
     1368                                  struct multi_instance *mi,
     1369                                  const struct plugin_return *pr,
     1370                                  unsigned int option_permissions_mask,
     1371                                  unsigned int *option_types_found)
     1372{
     1373  struct plugin_return config;
    13651374
     1375  plugin_return_get_column (pr, &config, "config");
     1376
     1377  /* Did script generate a dynamic config file? */
     1378  if (plugin_return_defined (&config))
     1379    {
     1380      int i;
     1381      for (i = 0; i < config.n; ++i)
     1382        {
     1383          if (config.list[i] && config.list[i]->value)
     1384            options_string_import (&mi->context.options,
     1385                                     config.list[i]->value,
     1386                                     D_IMPORT_ERRORS|M_OPTERR,
     1387                                     option_permissions_mask,
     1388                                     option_types_found,
     1389                                     mi->context.c2.es);
     1390        }
    13661391    }
    13671392}
    1368 
    1369 #endif
     1393#endif /* ENABLE_ACCOUNTING */
     1394#endif /* ENABLE_PLUGIN */
    13701395
    13711396#ifdef MANAGEMENT_DEF_AUTH
    13721397
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    14581483        | OPT_P_CONFIG
    14591484        | OPT_P_ECHO
    14601485        | OPT_P_COMP
    1461         | OPT_P_SOCKFLAGS;
     1486        | OPT_P_SOCKFLAGS
     1487        | OPT_P_ACCOUNTING;
    14621488
    14631489      int cc_succeeded = true; /* client connect script status */
    14641490      int cc_succeeded_count = 0;
    multi_connection_established (struct multi_context *m, struct multi_instance *mi 
    15271553
    15281554      /* do --client-connect setenvs */
    15291555      multi_client_connect_setenv (m, mi);
    1530 #ifdef ENABLE_ACCOUNTING
    1531               event_timeout_modify_wakeup (&mi->context.c2.accounting_interval, mi->context.options.accounting_freq);
    1532 #endif
    15331556
    15341557
    15351558#ifdef ENABLE_PLUGIN
    gremlin_flood_clients (struct multi_context *m) 
    23752398}
    23762399#endif
    23772400
    2378 /*
    2379  * Process timers in the top-level context
     2401#ifdef ENABLE_ACCOUNTING
     2402/**
     2403 * Process client instances accounting by invoking
     2404 * OPENVPN_PLUGIN_ACCOUNTING
    23802405 */
    2381 void
    2382 multi_process_per_second_timers_dowork (struct multi_context *m)
     2406void multi_client_accounting (struct multi_context *m)
    23832407{
    2384   /* possibly reap instances/routes in vhash */
    2385   multi_reap_process (m);
    23862408
    2387   /* possibly print to status log */
    2388   if (m->top.c1.status_output)
    2389     {
    2390       if (status_trigger (m->top.c1.status_output))
    2391         multi_print_status (m, m->top.c1.status_output, m->status_file_version);
    2392     }
    2393 #ifdef ENABLE_PLUGIN
    2394 #ifdef ENABLE_ACCOUNTING
    2395         /* for each client context if register to PLUGIN_STATS
     2409  const unsigned int option_permissions_mask = OPT_P_ACCOUNTING;
     2410  unsigned int option_types_found;
     2411  /* for each client context if register to PLUGIN_ACCOUNTING
    23962412   * and event should be triggered, send status to plugin
    2397    */   
    2398   if (plugin_defined (m->top.plugins, OPENVPN_PLUGIN_STATS))
     2413   */
     2414  if (plugin_defined (m->top.plugins, OPENVPN_PLUGIN_ACCOUNTING))
    23992415    {
    24002416      struct argv argv = argv_new ();
    24012417      if (m->hash)
    multi_process_per_second_timers_dowork (struct multi_context *m) 
    24052421          const struct hash_element *he;
    24062422   
    24072423          hash_iterator_init (m->hash, &hi, true);
     2424
    24082425          while ((he = hash_iterator_next (&hi)))
    24092426           {
    24102427             struct gc_arena gc = gc_new ();
    24112428             struct multi_instance *mi = (struct multi_instance *) he->value;
    24122429             if (!mi->halt)
    24132430               {
    2414                  struct context *client_context = &(mi->context);
     2431                 struct context *c = &mi->context;
    24152432                 struct timeval null;
    24162433                 CLEAR (null);
    2417                  if (event_timeout_trigger (&(client_context->c2.accounting_interval), &null, ETT_DEFAULT))
     2434                 if (event_timeout_defined (&c->c2.accounting_interval) &&
     2435                     event_timeout_trigger (&c->c2.accounting_interval, &null, ETT_DEFAULT))
    24182436                   {
    2419                      msg (M_DEBUG, "DEBUG: ACCOUNTING triggerred after %ds (%d) for %s",
    2420                                   client_context->options.accounting_freq, client_context->c2.accounting_interval.n,
    2421                               tls_common_name (client_context->c2.tls_multi, false));
    2422                      setenv_stats (client_context);
    2423                      if (plugin_call (client_context->plugins, OPENVPN_PLUGIN_STATS, &argv, NULL, client_context->c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
     2437#ifdef ENABLE_DEBUG
     2438                     msg (M_DEBUG, "DEBUG: ACCOUNTING triggerred after %ds for %s",
     2439                              c->c2.accounting_interval.n,
     2440                              tls_common_name (c->c2.tls_multi, false));
     2441#endif
     2442                     struct plugin_return pr;
     2443                     plugin_return_init (&pr);
     2444
     2445                     option_types_found = 0;
     2446                     setenv_stats (c);
     2447                     if (plugin_call (c->plugins, OPENVPN_PLUGIN_ACCOUNTING, &argv, &pr, c->c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
    24242448                       {
    24252449                         msg (M_WARN, "WARNING: stats plugin call failed");
    24262450                       }
     2451                     else
     2452                       {
     2453                         multi_accounting_post_plugin (m, mi, &pr, option_permissions_mask, &option_types_found);
     2454                         do_deferred_options (c, option_types_found);
     2455                       }
     2456                         plugin_return_free (&pr);
    24272457                   }
    24282458               }
    24292459             gc_free (&gc);
    multi_process_per_second_timers_dowork (struct multi_context *m) 
    24322462        }
    24332463      argv_reset (&argv);
    24342464    }
    2435 #endif /* ENABLE_ACCOUNTING */
    2436 #endif /* ENABLE_PLUGIN */
     2465}
     2466#endif
     2467
     2468/*
     2469 * Process timers in the top-level context
     2470 */
     2471void
     2472multi_process_per_second_timers_dowork (struct multi_context *m)
     2473{
     2474  /* possibly reap instances/routes in vhash */
     2475  multi_reap_process (m);
     2476
     2477  /* possibly print to status log */
     2478  if (m->top.c1.status_output)
     2479    {
     2480      if (status_trigger (m->top.c1.status_output))
     2481        multi_print_status (m, m->top.c1.status_output, m->status_file_version);
     2482    }
     2483
     2484#if defined(ENABLE_PLUGIN) && defined(ENABLE_ACCOUNTING)
     2485  multi_client_accounting (m);
     2486#endif
     2487
    24372488  /* possibly flush ifconfig-pool file */
    24382489  multi_ifconfig_pool_persist (m, false);
    24392490
  • openvpn-plugin.h

    diff --git a/openvpn-plugin.h b/openvpn-plugin.h
    index bb5fd39..44e62a6 100644
    a b  
    9797#define OPENVPN_PLUGIN_CLIENT_CONNECT_V2     9
    9898#define OPENVPN_PLUGIN_TLS_FINAL             10
    9999#define OPENVPN_PLUGIN_ENABLE_PF             11
    100 #define OPENVPN_PLUGIN_STATS                 12
     100#define OPENVPN_PLUGIN_ACCOUNTING            12
    101101#define OPENVPN_PLUGIN_N                     13
    102102
    103103/*
  • openvpn.h

    diff --git a/openvpn.h b/openvpn.h
    index 08f1b3d..a4711c6 100644
    a b struct context_2 
    305305  int occ_mtu_load_n_tries;
    306306#endif
    307307
    308 #ifdef ENABLE_ACCOUNTING
     308#if defined(ENABLE_PLUGIN) && defined(ENABLE_ACCOUNTING)
    309309  struct event_timeout accounting_interval;
    310310#endif
    311311
  • options.c

    diff --git a/options.c b/options.c
    index bc04aa3..05bf37c 100644
    a b add_option (struct options *options, 
    57565756    {
    57575757      int freq;
    57585758
    5759       VERIFY_PERMISSION (OPT_P_INSTANCE | OPT_P_GENERAL);
     5759      VERIFY_PERMISSION (OPT_P_ACCOUNTING);
    57605760      freq = atoi (p[1]);
    57615761      if (freq < 0)
    57625762  {
  • options.h

    diff --git a/options.h b/options.h
    index 0f66f7a..ebfb621 100644
    a b struct options 
    406406#endif
    407407
    408408#ifdef ENABLE_ACCOUNTING
    409   int accounting_freq; 
     409  int accounting_freq;
    410410#endif
    411411
    412412#ifdef USE_CRYPTO
    struct options 
    548548#define OPT_P_SOCKBUF         (1<<25)
    549549#define OPT_P_SOCKFLAGS       (1<<26)
    550550#define OPT_P_CONNECTION      (1<<27)
     551#define OPT_P_ACCOUNTING      (1<<28)
    551552
    552553#define OPT_P_DEFAULT   (~(OPT_P_INSTANCE|OPT_P_PULL_MODE))
    553554
  • plugin.c

    diff --git a/plugin.c b/plugin.c
    index 9d0563d..a0ee535 100644
    a b plugin_type_name (const int type) 
    8888      return "PLUGIN_TLS_FINAL";
    8989    case OPENVPN_PLUGIN_ENABLE_PF:
    9090      return "OPENVPN_PLUGIN_ENABLE_PF";
    91     case OPENVPN_PLUGIN_STATS:
    92       return "OPENVPN_PLUGIN_STATS";
     91    case OPENVPN_PLUGIN_ACCOUNTING:
     92      return "OPENVPN_PLUGIN_ACCOUNTING";
    9393    default:
    9494      return "PLUGIN_???";
    9595    }
  • init.c

    -- 
    1.7.0.4
    
    
    From 1728b04986a31fb587553a41a991b402fb0fb9e4 Mon Sep 17 00:00:00 2001
    From: chantra <chantra@debuntu.org>
    Date: Sun, 6 Jun 2010 07:46:16 +0200
    Subject: Double checking that ENABLE_PLUGIN is defined
    
    There is no reason to enable the feature if
    ENABLE_PLUGIN is not defined in the first place
    Signed-off-by: chantra <chantra@debuntu.org>
    ---
     init.c    |    2 +-
     multi.c   |    3 +--
     options.c |    8 ++++----
     options.h |    2 +-
     4 files changed, 7 insertions(+), 8 deletions(-)
    
    diff --git a/init.c b/init.c
    index c60617d..4d4a7c2 100644
    a b do_init_timers (struct context *c, bool deferred) 
    870870        event_timeout_init (&c->c2.occ_mtu_load_test_interval, OCC_MTU_LOAD_INTERVAL_SECONDS, now);
    871871#endif
    872872
    873 #ifdef ENABLE_ACCOUNTING
     873#if defined(ENABLE_PLUGIN) && defined(ENABLE_ACCOUNTING)
    874874      if (c->options.accounting_freq)
    875875  event_timeout_init (&c->c2.accounting_interval, c->options.accounting_freq, now);
    876876#endif
  • multi.c

    diff --git a/multi.c b/multi.c
    index f6c70d9..a467580 100644
    a b void multi_client_accounting (struct multi_context *m) 
    24312431                 struct context *c = &mi->context;
    24322432                 struct timeval null;
    24332433                 CLEAR (null);
    2434                  if (event_timeout_defined (&c->c2.accounting_interval) &&
    2435                      event_timeout_trigger (&c->c2.accounting_interval, &null, ETT_DEFAULT))
     2434                 if (event_timeout_trigger (&c->c2.accounting_interval, &null, ETT_DEFAULT))
    24362435                   {
    24372436#ifdef ENABLE_DEBUG
    24382437                     msg (M_DEBUG, "DEBUG: ACCOUNTING triggerred after %ds for %s",
  • options.c

    diff --git a/options.c b/options.c
    index 05bf37c..8d33490 100644
    a b static const char usage_message[] = 
    307307  "--status file n : Write operational status to file every n seconds.\n"
    308308  "--status-version [n] : Choose the status file format version number.\n"
    309309  "                  Currently, n can be 1, 2, or 3 (default=1).\n"
    310 #ifdef ENABLE_ACCOUNTING
     310#if defined(ENABLE_PLUGIN) && defined(ENABLE_ACCOUNTING)
    311311  "--accounting-freq s : Send client accounting information every s seconds.\n"
    312312#endif
    313313#ifdef ENABLE_OCC
    init_options (struct options *o, const bool init_gc) 
    694694#ifdef ENABLE_OCC
    695695  o->occ = true;
    696696#endif
    697 #ifdef ENABLE_ACCOUNTING
     697#if defined(ENABLE_PLUGIN) && defined(ENABLE_ACCOUNTING)
    698698  o->accounting_freq = 60;
    699699#endif
    700700#ifdef ENABLE_MANAGEMENT
    show_settings (const struct options *o) 
    13881388  show_p2mp_parms (o);
    13891389#endif
    13901390
    1391 #ifdef ENABLE_ACCOUNTING
     1391#if defined(ENABLE_PLUGIN) && defined(ENABLE_ACCOUNTING)
    13921392  SHOW_INT (accounting_freq);
    13931393#endif
    13941394
    add_option (struct options *options, 
    57515751      options->persist_mode = 1;
    57525752    }
    57535753#endif
    5754 #ifdef ENABLE_ACCOUNTING
     5754#if defined(ENABLE_PLUGIN) && defined(ENABLE_ACCOUNTING)
    57555755  else if (streq (p[0], "accounting-freq") && p[1])
    57565756    {
    57575757      int freq;
  • options.h

    diff --git a/options.h b/options.h
    index ebfb621..19dfd4c 100644
    a b struct options 
    405405
    406406#endif
    407407
    408 #ifdef ENABLE_ACCOUNTING
     408#if defined(ENABLE_PLUGIN) && defined(ENABLE_ACCOUNTING)
    409409  int accounting_freq;
    410410#endif
    411411