8000 openvpn: reworked status file parser by rpv-tomsk · Pull Request #2352 · collectd/collectd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

openvpn: reworked status file parser #2352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2017
Merged

Conversation

rpv-tomsk
Copy link
Contributor
  • Added detection of status fields index by parsing 'HEADER' lines.
    This allows to support status files from latest OpenVPN-2.4 and possible from future versions;
  • Fixed a bug with OpenVPN status file version 3 where delimiter is 'tab' (not space or comma);
  • Status file version detection was moved from configuration callback to read callback;
  • Now 'plugin_register_complex_read()' is used for registering read callbacks.

Closes: #2128

@rpv-tomsk rpv-tomsk force-pushed the openvpn-2.4 branch 2 times, most recently from 1a79b57 to e30ec78 Compare July 8, 2017 19:05
@rpv-tomsk
Copy link
Contributor Author

I have checked this on my setups. Status files of 'SINGLE' , 'MULTI' version 1, version 2, version 3 formats from OpenVPN-2.2; 'MULTI' version 2 status file from OpenVPN-2.4 was checked.

@octo, @rubenk - I offer this already polished PR to your attention. Let's review and merge it?
I will be happy to answer your questions.

rpv-tomsk referenced this pull request Jul 9, 2017
make  all-am
make[1]: Entering directory '/home/ruben/src/collectd'
  CC       src/snmp_agent_la-snmp_agent.lo
In file included from ./src/daemon/common.h:33:0,
                 from src/snmp_agent.c:31:
src/snmp_agent.c: In function ‘snmp_agent_dump_data’:
src/snmp_agent.c:42:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
 #define PLUGIN_NAME "snmp_agent"
                     ^
./src/daemon/plugin.h:400:42: note: in definition of macro ‘DEBUG’
 #define DEBUG(...) plugin_log(LOG_DEBUG, __VA_ARGS__)
                                          ^~~~~~~~~~~
src/snmp_agent.c:192:13: note: in expansion of macro ‘PLUGIN_NAME’
       DEBUG(PLUGIN_NAME ":   OID[%d]: %s", i, oid_str);
             ^~~~~~~~~~~
src/snmp_agent.c:192:35: note: format string is defined here
       DEBUG(PLUGIN_NAME ":   OID[%d]: %s", i, oid_str);
                                  ~^
                                  %ld
  CCLD     snmp_agent.la
@rpv-tomsk rpv-tomsk force-pushed the openvpn-2.4 branch 2 times, most recently from af9df00 to 7350e97 Compare July 9, 2017 15:27
Copy link
Member
@octo octo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rpv-tomsk,

thank you very much for your patch! It looks great overall! One issue is that we removed ssnprintf() in the mean time and since I had the review started, I've left a couple more style nits … sorry ;-)

Best regards,
—octo

src/openvpn.c Outdated

int status;

ssnprintf(callback_name, sizeof(callback_name), "openvpn/%s", status_name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ssnprintf() has been removed (be12604), use snprintf() instead.

src/openvpn.c Outdated
temp = malloc(sizeof(*temp));
if (temp == NULL) {
/* create a new vpn element */
instance = malloc(sizeof(*instance));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use calloc() instead.

src/openvpn.c Outdated
value);
return 1;
}
vpn_status_t *instance;

status_file = sstrdup(value);
if (status_file == NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't make sense, since the difference between strdup() and sstrdup() is that the latter exits. I'd prefer to switch to strdup() here (and leave the error handling). Unfortunately I haven't found the energy to remove the uses of sstrdup() globally yet.

src/openvpn.c Outdated
* better play it save. */
if ((filename == NULL) || (*filename == 0))
return 0;
vpn_status_t *st;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare and initialize in one line, if possible:

vpn_status_t *st = user_data->data;

src/openvpn.c Outdated
long long sum_users = 0;

int found_header = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this should be a _Bool

 * Added detection of status fields index by parsing 'HEADER' lines.
   This allows to support status files from latest OpenVPN-2.4 and possible from future versions;
 * Fixed a bug with OpenVPN status file version 3 where delimiter is 'tab' (not space or comma);
 * Status file version detection was moved from configuration callback to read callback;
 * Now 'plugin_register_complex_read()' is used for registering read callback.

Closes: collectd#2128
@rpv-tomsk
Copy link
Contributor Author

Hi, Florian! Glad to get your feedback!

The patch is rebased to current master, 'nits' are fixed, code passed through clang-format.

Copy link
Member
@octo octo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thanks for the cleanup of unrelated code @rpv-tomsk!

@octo octo merged commit 5dcc047 into collectd:master Sep 21, 2017
@octo octo added this to the 5.8 milestone Oct 11, 2017
@rpv-tomsk rpv-tomsk deleted the openvpn-2.4 branch July 5, 2018 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0